Converting FindScanline assembly code to purepascal
I am trying to convert some Delphi 5 code to Delphi XE7-x64 and I am stuck on following code:
function FindScanline(Source : Pointer; MaxLen : Cardinal;
Value : Cardinal) : Cardinal; assembler;
asm
PUSH ECX
MOV ECX,EDX
MOV EDX,EDI
MOV EDI,EAX
POP EAX
REPE SCASB
MOV EAX,ECX
MOV EDI,EDX
end;
As far as I understand following things are occuring:
push the contents of ECX register(Value) onto the stack move contents of EDX register(MaxLen) into ECX register. now ECX holds (MaxLen) move contents of EDI register into EDX register. now EDX holds (EDI) move contents of EAX register into EDI register. now EDI holds (Source) pop ECX into EDX. now EDX holds (Value). Was (EDI) lost? repeat while equal ?decrement ECX for each char? move contents of ECX register into EAX register move contents of EDX register into EDI register
For reference function FindScanline is used in function GetCursorHeightMargin
Any help in translating above will be appreciated.
Here is a literal translation:
function FindScanline(Source: Pointer; MaxLen: Cardinal; Value: Cardinal): Cardinal;
var
Ptr: PByte;
begin
Result := MaxLen;
if Result > 0 then
dec(Result);
Ptr := Source;
while (Result > 0) and (Ptr^ = Value) do
begin
inc(Ptr);
dec(Result);
end;
end;
It's rather messy to handle the edge cases unfortunately.
链接地址: http://www.djcxy.com/p/15902.html上一篇: 在堆栈中使用空闲寄存器的顺序