background image

8-2 Vol. 1

PROGRAMMING WITH THE X87 FPU

results can be left in the double extended-precision floating-point format or converted back into a shorter floating-
point format, an integer format, or the packed BCD integer format. (See Section 8.2, “x87 FPU Data Types,” for 
description of the data types operated on by the x87 FPU.)

The x87 FPU instructions treat the eight x87 FPU data registers as a register stack (see Figure 8-2). All addressing of 
the data registers is relative to the register on the top of the stack. The register number of the current top-of-stack 
register is stored in the TOP (stack TOP) field in the x87 FPU status word. Load operations decrement TOP by one 
and load a value into the new top-of-stack register, and store operations store the value from the current TOP 
register in memory and then increment TOP by one. (For the x87 FPU, a load operation is equivalent to a push and 
a store operation is equivalent to a pop.) Note that load and store operations are also available that do not push and 
pop the stack.

If a load operation is performed when TOP is at 0, register wraparound occurs and the new value of TOP is set to 7. 
The floating-point stack-overflow exception indicates when wraparound might cause an unsaved value to be over-
written (see Section 8.5.1.1, “Stack Overflow or Underflow Exception (#IS)”).
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 support these 

Figure 8-1.  x87 FPU Execution Environment

Figure 8-2.  x87 FPU Data Register Stack

0

79

R7

R6

R5

R4

R3

R2

R1

R0

Data Registers

Exponent

Significand

78

64 63

15

Control

Register

0

Status

Register

Tag

Register

0

47

Last Instruction Pointer (FCS:FIP)

Last Data (Operand) Pointer (FDS:FDP)

10

Opcode

0

Sign

7

6

5

4

3

2

1

0

FPU Data Register Stack

ST(2)

ST(1)

ST(0)

Top

011B

Growth

Stack