F
felixsun
Unregistered / Unconfirmed
GUEST, unregistred user!
我没在delphi中找到xorbuf 这类的函数, 就自己试着写了写,但效率不是很高,请高人帮助修改,这也是我第一次写 嵌入式汇编,
procedure XorBufAsm(D, S: Pointer
Count: Integer);
asm
push eax;
push ebx;
push ecx;
push edx;
dec edx
dec eax
test ecx,ecx
jz @2
@1:
mov bh,BYTE [edx+ecx]
xor Byte [eax+ecx], bh
dec ecx;
jnz @1;
@2:
pop edx;
pop ecx;
pop ebx;
pop eax;
end;
procedure XorBufAsm2(D, S: Pointer
Count: Integer);
asm
push eax;
push ebx;
push ecx;
push edx;
mov ebx,ecx;
and ebx,$3;
jz @2
shl ebx,8;
@1:
mov bl,BYTE [edx+ecx-1]
xor [eax+ecx-1], bl
dec ecx;
dec bh;
jnz @1;
@2:
shr ecx,2
jz @4
sub edx,4
sub eax,4
@3:
mov ebx,[edx+ecx*4]
xor [eax+ecx*4] ,ebx
dec ecx;
jnz @3;
@4:
pop edx;
pop ecx;
pop ebx;
pop eax;
end;
procedure XorBuf1(D, S: Pointer
Count: Integer);
var
i: Integer;
tmpByte: integer;
begin
for i := 0 to Count-1 do
begin
Byte((PChar(D) + i)^) := Byte((PChar(D) + i)^) xor Byte((PChar(S) + i)^);
end;
end;
procedure XorBuf2(D, S: Pointer
Count: Integer);
type
TIntegerArray = array[0..MaxInt div 8 - 1] of Integer;
PIntegerArray = ^TIntegerArray;
var
i, b: Integer;
begin
b := Count mod 4;
for i := 1 to b do
begin
Byte((PChar(D) + Count - i)^) := Byte((PChar(D) + Count - i)^) xor Byte((PChar(S) + Count - i)^);
end;
for i := 0 to (Count div 4) - 1 do
PIntegerArray(D)^ := PIntegerArray(D)^ xor PIntegerArray(S)^;
end;
procedure XorBufAsm(D, S: Pointer
Count: Integer);
asm
push eax;
push ebx;
push ecx;
push edx;
dec edx
dec eax
test ecx,ecx
jz @2
@1:
mov bh,BYTE [edx+ecx]
xor Byte [eax+ecx], bh
dec ecx;
jnz @1;
@2:
pop edx;
pop ecx;
pop ebx;
pop eax;
end;
procedure XorBufAsm2(D, S: Pointer
Count: Integer);
asm
push eax;
push ebx;
push ecx;
push edx;
mov ebx,ecx;
and ebx,$3;
jz @2
shl ebx,8;
@1:
mov bl,BYTE [edx+ecx-1]
xor [eax+ecx-1], bl
dec ecx;
dec bh;
jnz @1;
@2:
shr ecx,2
jz @4
sub edx,4
sub eax,4
@3:
mov ebx,[edx+ecx*4]
xor [eax+ecx*4] ,ebx
dec ecx;
jnz @3;
@4:
pop edx;
pop ecx;
pop ebx;
pop eax;
end;
procedure XorBuf1(D, S: Pointer
Count: Integer);
var
i: Integer;
tmpByte: integer;
begin
for i := 0 to Count-1 do
begin
Byte((PChar(D) + i)^) := Byte((PChar(D) + i)^) xor Byte((PChar(S) + i)^);
end;
end;
procedure XorBuf2(D, S: Pointer
Count: Integer);
type
TIntegerArray = array[0..MaxInt div 8 - 1] of Integer;
PIntegerArray = ^TIntegerArray;
var
i, b: Integer;
begin
b := Count mod 4;
for i := 1 to b do
begin
Byte((PChar(D) + Count - i)^) := Byte((PChar(D) + Count - i)^) xor Byte((PChar(S) + Count - i)^);
end;
for i := 0 to (Count div 4) - 1 do
PIntegerArray(D)^ := PIntegerArray(D)^ xor PIntegerArray(S)^;
end;