私が継承した最近のDelphiプロジェクトには、ASMにプロシージャがあります。私は完全なASM初心者なので、理解できません。プロシージャフローを解読するためにさまざまなASM命令を読みましたが、それでもわかりません。
ASMの経験がある人が私の理解を助け、次の手順を英語に翻訳できますか(その後、Delphiに翻訳し直して、コードが将来読みやすくなります!!!)
Mem1の宣言は、バイトの配列[0..15]です。。そして、Mem2はLongIntです。
手順は次のとおりです。
procedure TForm1.XorMem(var Mem1; const Mem2; Count : Cardinal); register;
begin
asm
push esi
push edi
mov esi, eax //esi = Mem1
mov edi, edx //edi = Mem2
push ecx //save byte count
shr ecx, 2 //convert to dwords
jz @Continue
cld
@Loop1: //xor dwords at a time
mov eax, [edi]
xor [esi], eax
add esi, 4
add edi, 4
dec ecx
jnz @Loop1
@Continue: //handle remaining bytes (3 or less)
pop ecx
and ecx, 3
jz @Done
@Loop2: //xor remaining bytes
mov al, [edi]
xor [esi], al
inc esi
inc edi
dec ecx
jnz @Loop2
@Done:
pop edi
pop esi
end;
end;
編集:Roman Rのおかげで、ASMをDelphiに戻しました
procedure TForm1.XorMem2(var Mem1; const Mem2 :LongInt; Count : Cardinal);
var
Key : array [0..3] of byte absolute Mem1;
Num : array [0..3] of byte absolute Mem2;
idx : byte;
begin
for Idx := 0 to Count -1 do Key[idx] := Key[idx] Xor Num[idx];
end;