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
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?
Change
JL
toJB
, since you can only do unsigned comparisons with the FPU flags.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.
FCOMx Sets the Control bits C3,C2,C0 according to the conditions
OTOH, the branch codes are implemented as
Thus: Behaviourally C3/EQ == Zero and C0/LT == Carry
References: Art of Assembly, FLAGS register, Conditional Jumps