FPU IA-32 SIGFPE,算术异常 [英] FPU IA-32 SIGFPE, Arithmetic exception
问题描述
我有这个code以下的问题。它是在IA-32架构气体汇编语法。它产生算术异常, FSQRT
指令之后。 SetDouble
是 INT
类型的值 0x0200
和输入
是一个浮点数。我使用的GCC与 -m32
标志编译这一点。在哪里可以我犯的错误有人点。
pushl%EBP
MOVL%ESP,EBP%
FINIT
FLDCW SetDouble
FLD输入
FLD输入
fmulp
FLD1
FADDP
FSQRT
FLD1
FXCH
FSUBP
FSTP输出
MOV%EBP,ESP%
流行的%ebp
控制字设置为0x200切换FPU翻一番precision和取消屏蔽所有异常,包括precision例外。因此对于大多数的输入(可能是一切,除了0), FSQRT
将引发此异常,这就是你所看到的。
您可以设置控制字来代替0x220掩盖precision例外。
I have a problem with this code below. It is GAS asm syntax on IA-32 architecture. It generates arithmetic exception, after fsqrt
instruction. SetDouble
is int
type of value 0x0200
and input
is a float number. I'm compiling this with -m32
flag using gcc. Can someone point where I made mistake.
pushl %ebp
movl %esp,%ebp
finit
fldcw SetDouble
fld input
fld input
fmulp
fld1
faddp
fsqrt
fld1
fxch
fsubp
fstp output
mov %ebp,%esp
pop %ebp
Setting the control word to 0x200 switches the FPU to double precision and unmasks all exceptions including the precision exception. As such for most inputs (probably everything except 0) the fsqrt
will raise this exception and that's what you are seeing.
You can set the control word to 0x220 instead to mask the precision exception.
这篇关于FPU IA-32 SIGFPE,算术异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!