Assembly Language for Beginners

(Jeff_L) #1

1.19. FLOATING-POINT UNIT


Next: theFADDPhas been executed, now the result of the addition is inST(0), andST(1)is cleared:


Figure 1.66:OllyDbg:FADDPhas been executed

The result is left inST(0), because the function returns its value inST(0).


main()takes this value from the register later.


We also see something unusual: the 13.93...value is now located inST(7). Why?


As we have read some time before in this book, theFPUregisters are a stack:1.19.2 on page 218. But
this is a simplification.


Imagine if it was implementedin hardwareas it’s described, then all 7 register’s contents must be moved
(or copied) to adjacent registers during pushing and popping, and that’s a lot of work.


In reality, theFPUhas just 8 registers and a pointer (calledTOP) which contains a register number, which
is the current “top of stack”.


When a value is pushed to the stack,TOPis pointed to the next available register, and then a value is
written to that register.


The procedure is reversed if a value is popped, however, the register which has been freed is not cleared
(it could possibly be cleared, but this is more work which can degrade performance). So that’s what we
see here.


It can be said thatFADDPsaved the sum in the stack, and then popped one element.


But in fact, this instruction saved the sum and then shiftedTOP.


More precisely, the registers of theFPUare a circular buffer.


GCC

Free download pdf