执行以下代码:
function ABCD32(Value: Cardinal): Single; register;
asm
BSWAP EAX
end;
function HexToFloat(hexValue: string; fmt: THexFloatFormat): Single;
var
c: Cardinal;
Err: Integer;
begin
Result := NaN;
c := HexToCardinal(hexValue, Err); //DCBA format
if Err <> 0 then Exit();
case fmt of
hfABCD: Result := ABCD32(c); //Here, after return from ABCD32
hfBADC: Result := BADC32(c);
hfCDAB: Result := CDAB32(c);
hfDCBA: Result := DCBA32(c);
end;
end;
导致运行时错误:
这是什么以及如何处理?
更新
这是CPU窗口输出:
HexFloat.dpr.162: hfABCD: Result := ABCD32(c);
004E98F8 8B45F0 mov eax,[ebp-$10]
004E98FB E894FFFFFF call ABCD32
004E9900 D95DF4 fstp dword ptr [ebp-$0c] //WTF?
004E9903 9B wait //Exception happens here
004E9904 EB28 jmp $004e992e
最佳答案
您的职能不尊重ABI。浮点值应在x87单元的ST(0)中返回。
function ABCD32(Value: Cardinal): Single; register;
asm
BSWAP EAX
PUSH EAX
FLD [ESP]
ADD ESP,4
end;
关于delphi - 调用汇编语言函数会导致 “floating point stack check”异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52256215/