7-11
FLOATING-POINT UNIT
Many floating-point instructions have several addressing modes that permit the programmer to
implicitly operate on the top of the stack, or to explicitly operate on specific registers relative to
the TOP. Assemblers supports these register addressing modes, using the expression ST(0), or
simply ST, to represent the current stack top and ST(i) to specify the ith register from TOP in
the stack (0
?
i
?
7). For example, if TOP contains 011B (register 3 is the top of the stack), the
following instruction would add the contents of two registers in the stack (registers 3 and 5):
FADD ST, ST(2);
Figure 7-7 shows an example of how the stack structure of the FPU registers and instructions
are typically used to perform a series of computations. Here, a two-dimensional dot product is
computed, as follows:
1.The first instruction
(
FLD value1
)
decrements the stack register pointer (TOP) and loads
the value 5.6 from memory into ST(0). The result of this operation is shown in snap-shot
(a).
2.The second instruction multiplies the value in ST(0) by the value 2.4 from memory and
stores the result in ST(0), shown in snap-shot (b).
3.The third instruction decrements TOP and loads the value 3.8 in ST(0).
4.The fourth instruction multiplies the value in ST(0) by the value 10.3 from memory and
stores the result in ST(0), shown in snap-shot (c).
5.The fifth instruction adds the value and the value in ST(1) and stores the result in ST(0),
shown in snap-shot (d).
The style of programming demonstrated in this example is supported by the floating-point
instruction set. In cases where the stack structure causes computation bottlenecks, the FXCH
(exchange FPU register contents) instruction can be used to streamline a computation.
7.3.1.1.PARAMETER PASSING WITH THE FPU REGISTER STACK
Like the general-purpose registers in the processors integer unit, the contents of the FPU data
registers are unaffected by procedure calls, or in other words, the values are maintained across
procedure boundaries. A calling procedure can thus use the FPU data registers (as well as the
procedure stack) for passing parameter between procedures. The called procedure can reference
parameters passed through the register stack using the current stack register pointer (TOP) and
the ST(0) and ST(i) nomenclature. It is also common practice for a called procedure to leave a
return value or result in register ST(0) when returning execution to the calling procedure or
program.