1.19. FLOATING-POINT UNIT
- And ifa=b, then:ZF=1, PF=0, CF=0.
Depending on the CPU flags and conditions,SETNBEstores 1 or 0 to AL. It is almost the counterpart of
JNBE, with the exception thatSETcc^126 stores 1 or 0 inAL, butJccdoes actually jump or not. SETNBE
stores 1 only ifCF=0andZF=0. If it is not true, 0 is to be stored intoAL.
Only in one case bothCFandZFare 0: ifa>b.
Then 1 is to be stored toAL, the subsequentJZis not to be triggered and the function will return _a. In all
other cases, _b is to be returned.
Optimizing GCC 4.4.1
Listing 1.213: Optimizing GCC 4.4.1
public d_max
d_max proc near
arg_0 = qword ptr 8
arg_8 = qword ptr 10h
push ebp
mov ebp, esp
fld [ebp+arg_0] ; _a
fld [ebp+arg_8] ; _b
; stack state now: ST(0) = _b, ST(1) = _a
fxch st(1)
; stack state now: ST(0) = _a, ST(1) = _b
fucom st(1) ; compare _a and _b
fnstsw ax
sahf
ja short loc_8048448
; store ST(0) to ST(0) (idle operation),
; pop value at top of stack,
; leave _b at top
fstp st
jmp short loc_804844A
loc_8048448:
; store _a to ST(1), pop value at top of stack, leave _a at top
fstp st(1)
loc_804844A:
pop ebp
retn
d_max endp
It is almost the same except thatJAis used afterSAHF. Actually, conditional jump instructions that check
“larger”, “lesser”or“equal”forunsignednumbercomparison(theseareJA,JAE,JB,JBE,JE/JZ,JNA,JNAE,
JNB,JNBE,JNE/JNZ) check only flagsCFandZF.
Let’s recall where bitsC3/C2/C0are located in theAHregister after the execution ofFSTSW/FNSTSW:
6 2 1 0
C3 C2C1C0
Let’s also recall, how the bits fromAHare stored into the CPU flags after the execution ofSAHF:
7 6 4 2 0
SFZF AF PF CF
After the comparison, theC3andC0bits are moved intoZFandCF, so the conditional jumps are able work
after.JAis triggering if bothCFareZFzero.
(^126) cciscondition code