Delphi XE2 64bit:GraphicEx中的inline asm

时间:2011-10-08 06:05:41

标签: delphi assembly delphi-xe2 basm graphicex

这会如何从asm变成纯粹的delphi?我无法编译需要GraphicEx的组件,在JPG单元中给出了一个错误,即内联汇编不支持64位。

function __ftol: Integer;
var
  f: double;
begin
  asm
    lea    eax, f             //  BC++ passes floats on the FPU stack
    fstp  qword ptr [eax]     //  Delphi passes floats on the CPU stack
  end;
  Result := Trunc(f);
end;

1 个答案:

答案 0 :(得分:1)

function __ftol( f : double) : Integer;
begin
  Result := Trunc(f);
end;

更新:对不起,我错了。进入此功能后,double将存储在FPU中。 然后将double放入局部var f并截断为整数。 所以忘了我的回答。

此例程未在GraphicEx中使用,因此请尝试将其注释掉。

更新2。

正如David所说,它可以被链接在.obj文件中使用。 假设它们是64位目标文件,执行相同的参数传递(在FPU堆栈中为double), 这是一个可以使用的函数(在64位模式下):

function __ftol : Integer;
// Assumes double value is in FPU stack on entry
// Make a truncation to integer and put it into function result
var
  TmpVal: Int64;
  SaveCW, ScratchCW: word;

asm
  .NOFRAME 

  fnstcw word ptr [SaveCW]
  fnstcw word ptr [ScratchCW]
  or word ptr [ScratchCW], 0F00h  ;// trunc toward zero, full precision
  fldcw word ptr [ScratchCW]
  fistp qword ptr [TmpVal]
  fldcw word ptr [SaveCW]
  mov rax, TmpVal
end;
相关问题