delphiassembly64-bitx86-64basm

64 bit inline assembly in Delphi XE3


I ran into this issue using 64-bit inline assembler in Delphi XE3 that I don't understand.

I tried this, and it works on both 32-bit and 64-bit

function test(a, b: integer): integer; assembler; register;
asm
  mov eax, a
  add eax, edx
end;

However, this only works on 32-bit but not 64-bit, in 64-bit it compiles, but did not return correct result of the sum of two integers.

function test(a, b: integer): integer; assembler; register;
asm
  add eax, edx
end;

I know previous FPU code such as FLD, STP works on 32-bit but it will give compilation error on 64-bit compiler. Any idea how to handle floating numbers in 64-bit ?


Solution

  • It is because 64-bit system uses own calling convention, and these parameters are in RCX and RDX registers. More explanations in MSDN.

    About handling floating numbers - read Intel developer documentation.