Assembly Language for Beginners

(Jeff_L) #1

1.19. FLOATING-POINT UNIT


; leave (_b) on top
fstp ST(0)


; current stack state: ST(0) = _b


ret 0
_d_max ENDP


FCOMdiffers fromFCOMPin the sense that it just compares the values and doesn’t change the FPU stack.
Unlike the previous example, here the operands are in reverse order, which is why the result of the com-
parison inC3/C2/C0is different:



  • Ifa>bin our example, thenC3/C2/C0bits are to be set as: 0, 0, 0.

  • Ifb>a, then the bits are: 0, 0, 1.

  • Ifa=b, then the bits are: 1, 0, 0.


Thetest ah, 65instruction leaves just two bits —C3andC0. Both will be zero ifa>b: in that case the
JNEjump will not be triggered. ThenFSTP ST(1)follows —this instruction copies the value fromST(0)to
the operand and pops one value from the FPU stack. In other words, the instruction copiesST(0)(where
the value of_ais now) intoST(1). After that, two copies of _a are at the top of the stack. Then, one value
is popped. After that,ST(0)contains _a and the function is finishes.


The conditional jumpJNEis triggering in two cases: ifb>aora=b.ST(0)is copied intoST(0), it is just
like an idle (NOP) operation, then one value is popped from the stack and the top of the stack (ST(0)) is
contain what has been inST(1)before (that is _b). Then the function finishes. The reason this instruction
isusedhereprobablyisbecausetheFPUhasnootherinstructiontopopavaluefromthestackanddiscard
it.

Free download pdf