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

Ale*_*xis -3 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;
}
Run Code Online (Sandbox Code Playgroud)

这是我的德尔福尝试

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;
Run Code Online (Sandbox Code Playgroud)

非常感谢

Lee*_*ver 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;
Run Code Online (Sandbox Code Playgroud)

  • 原始asm没有反转参数.代码:"Ac"(A1),"d"(Ac)表示:将Al变量放入ecx寄存器,将Ac变量放入edx寄存器.德尔福按照以下顺序对params进行调整:eax,edx,ecx,stack; 所以为了保持函数签名相同,我们交换传递的参数.PS.该函数调用Amem参数指向的另一个函数 (2认同)
  • 感谢那.FWIW,我认为你的答案将得益于包含对编译器是什么,语法是什么,param映射是什么以及原始代码的作用和Pascal代码的作用的一些细节的解释.我怀疑它会得到更多的赞成,而Q可能还没有被关闭. (2认同)