执行以下代码:
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;
导致运行时错误:
Project HexFloat.exe raised exception class $C0000092 with message ‘floating point stack check at 0x004e9903’.
这是什么以及如何处理它?
更新
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;