将FindScanline汇编代码转换为purepascal

我试图将一些德尔福5代码转换为Delphi XE7-x64,我坚持下面的代码:

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; 

据我了解以下事情正在发生:

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

对于引用函数FindScanline用于函数GetCursorHeightMargin

任何帮助翻译上面将不胜感激。


这是一个直译:

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;

处理边缘情况很不幸。

链接地址: http://www.djcxy.com/p/15901.html

上一篇: Converting FindScanline assembly code to purepascal

下一篇: execv example is segfaulting