德尔福XE2 64位: inline asm in GraphicEx

标签 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;

最佳答案

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

更新:抱歉我错了。进入该函数后, double 值将存储在 FPU 中。 然后将 double 放入局部 var f 并截断为整数。 所以忘记我的回答吧。

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

更新2。

正如 David 所说,它可以通过在 .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;

关于德尔福XE2 64位: inline asm in GraphicEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695108/

相关文章:

delphi - 音频文件标记(读/写)库?

Delphi:显示窗口而不激活

performance - 条件指令(cmov)和跳转指令之间的区别

delphi - 在某些组件上更改鼠标光标而不影响其他光标设置代码

delphi - 检查记录字段是否唯一(DBTables.TBDEDataSet.Lookup 方法)

delphi - System.IOUtils 中的 TPath 记录在哪里初始化?

delphi - 禁用 vcl 控件上的热键

Delphi:查找对话框和字符串网格

linux - 如何切换gdb字节输出分组

assembly - 了解汇编 MIPS .ALIGN 和内存寻址