FCOM浮点比较失败 [英] FCOM floating point comparison fails
问题描述
我刚刚开始使用32位汇编,我很困惑.我有以下代码:
I am just getting started with 32-bit assembly and I'm quite confused. I have the following code:
.586
.MODEL FLAT
.STACK 4096
.DATA
.CODE
main PROC
finit
fldpi
fld1
fcom
fstsw ax
sahf
JL jumper
nop
jumper:
nop
nop
main ENDP
END
现在,据我所知,我将pi推入堆栈,然后将1推入堆栈,它应该将pi和1进行比较,看得出1较小,然后执行跳转.但是,比较似乎不起作用.有人可以帮忙吗?
Now from what I understand, I am pushing pi onto the stack then pushing 1 onto the stack, it should compare pi and 1 and see that 1 is lesser and execute a jump. However the comparison doesn't appear to work. Can someone help?
推荐答案
将JL
更改为JB
,因为您只能使用FPU标志进行 unsigned 比较.
Change JL
to JB
, since you can only do unsigned comparisons with the FPU flags.
原因是8087在与8086相同的位置只有2个等效状态位.它们是CF和ZF.在进行带符号的比较时,处理器使用任何先前操作的OF状态并将8087忙状态作为符号位.
The reason is that 8087 has only 2 equivalent status bits at the same positions as 8086. Those are CF and ZF. When doing a signed comparison, the processor uses OF state from any preceding operation and the 8087 Busy State as the sign bit.
8087: [Busy] [ EQ ] [ Top of Stack Ptr ] [UND] [SOF] [ LT ]
C3 C2 C1 C0 <-- C3..C0
8086: [Sign] [Zero] [ 0 ] [ AF ] [ 0 ] [PF ] [ 1 ] [ C ]
FCOMx根据条件设置控制位C3,C2,C0
FCOMx Sets the Control bits C3,C2,C0 according to the conditions
C3 = EQ == equal
C2 = Undefined == Set if ST or Mem is undefined
C1 = Marks either Underflow or Overflow of FP Stack (If Overflow Exception == TRUE)
C0 = True, if ST(i) < ST(1)/Mem
OTOH,分支代码实现为
OTOH, the branch codes are implemented as
JL: SF != OF
JB: CF
JBE: CF | ZF
JA: !CF && !ZF
因此:行为C3/EQ ==零,C0/LT ==携带
Thus: Behaviourally C3/EQ == Zero and C0/LT == Carry
这篇关于FCOM浮点比较失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!