gpt4 book ai didi

德尔福XE2 64位: inline asm in GraphicEx

转载 作者:行者123 更新时间:2023-12-03 15:58:39 25 4
gpt4 key购买 nike

从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com