将C ++内联汇编程序函数转换为delphi内联汇编程序函数

时间:2012-01-17 11:35:48

标签: c++ c delphi assembly

请问这个C ++函数如何转换为Delphi:

int To_Asm_Fnc(dword Amem, dword Al, dword Ac) {
int b = 0;
    asm ("push %%ecx; \
             call %%eax; \
             pop  %%ecx;"
         : "=Al" (b) /* output value */
         : "Al" (mem), "Ac" (Al), "d" (Ac) /* input value */
         );
    return b;
}

这是我的delphi尝试

Function To_Asm_Fnc(Amem,Al,Ac:dword):Integer;
var
b:Integer;
begin
Result:=0;
b:=0;
//*******
{ i really didn't get it as in the c++ code }
//*******
Result:=b;
end;
非常感谢

1 个答案:

答案 0 :(得分:6)

似乎此函数接受指向另一个函数的指针并设置参数

function To_Asm_Fnc(Amem: Pointer; _Al, _Ac: cardinal): integer;
asm
  // x68 only!; paramateres are passed differently in x64
  // inputs : "Al" (mem), "Ac" (Al), "d" (Ac) /* input value */
  // amem is already in eax
  // _al is passed in edx and _ac in ecx; but the code expects them reversed
  xchg edx, ecx
  push ecx
  call eax
  pop  ecx
  // result is already in eax and delphi returns the result in eax
  // outputs : "=Al" (b) /* output value */
end;