【问题标题】:Delphi XE2 64bit: inline asm in GraphicExDelphi XE2 64bit:GraphicEx 中的内联 asm
【发布时间】:2011-10-08 06:05:41
【问题描述】:

这将如何从 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;

【问题讨论】:

  • ftol 通常包含在链接到使用 bcc32 编译的 .obj 文件时。这就是这里发生的事情吗?

标签: delphi assembly delphi-xe2 basm graphicex


【解决方案1】:
function __ftol( f : double) : Integer;
begin
  Result := Trunc(f);
end;

更新:对不起,我错了。进入此函数时,双精度值存储在 FPU 中。 然后将 double 放入本地 var f 并截断为整数。 所以忘记我的回答吧。

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

更新 2。

正如大卫所说,它可以被 .obj 文件中的链接使用。 假设它们是执行相同参数传递的 64 位目标文件(FPU 堆栈中的双倍), 这是一个可以使用的函数(在 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;

【讨论】:

  • 虽然 GraphicsEx 没有明确使用该例程,但它可能被链接到 GraphicsEx 单元之一的 .obj 文件使用。
  • 不要假设参数传递在 64 位中是相同的。完全不同的 ABI。
  • @David,正确,这种类型的参数传递约定是 linux/GCC 在 32 位中使用的。在 64 位中,它的完成方式不同,请参阅 X86_calling_conventions
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多