[英]FCOM floating point comparison fails
I am just getting started with 32-bit assembly and I'm quite confused. 我刚刚开始使用32位汇编,我很困惑。 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
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. 现在,据我了解,我将pi压入堆栈,然后将1压入堆栈,它应该比较pi和1并看到1较小,然后执行跳转。 However the comparison doesn't appear to work.
但是,比较似乎不起作用。 Can someone help?
有人可以帮忙吗?
Change JL
to JB
, since you can only do unsigned comparisons with the FPU flags. 将
JL
更改为JB
,因为您只能使用FPU标志进行无符号比较。
The reason is that 8087 has only 2 equivalent status bits at the same positions as 8086. Those are CF and ZF. 原因是8087在与8086相同的位置只有2个等效状态位。它们是CF和ZF。 When doing a signed comparison, the processor uses OF state from any preceding operation and the 8087 Busy State as the sign bit.
在进行带符号的比较时,处理器使用任何先前操作的OF状态并将8087繁忙状态用作符号位。
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 Sets the Control bits C3,C2,C0 according to the conditions FCOMx根据条件设置控制位C3,C2,C0
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, the branch codes are implemented as OTOH,将分支代码实现为
JL: SF != OF
JB: CF
JBE: CF | ZF
JA: !CF && !ZF
Thus: Behaviourally C3/EQ == Zero and C0/LT == Carry 因此:行为C3 / EQ ==零和C0 / LT ==进位
References: Art of Assembly , FLAGS register , Conditional Jumps 参考文献: 装配艺术 , FLAGS寄存器 , 条件跳转
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.