background image

8-4 Vol. 1

PROGRAMMING WITH THE X87 FPU

When mixing MMX and x87 FPU instructions in the procedures or code sequences, the programmer is responsible 
for maintaining the integrity of parameters being passed in the x87 FPU data registers. If an MMX instruction is 
executed before the parameters in the x87 FPU data registers have been passed to another procedure, the param-
eters may be lost (see Section 9.5, “Compatibility with x87 FPU Architecture”).

8.1.3 

x87 FPU Status Register

The 16-bit x87 FPU status register (see Figure 8-4) indicates the current state of the x87 FPU. The flags in the x87 
FPU status register include the FPU busy flag, top-of-stack (TOP) pointer, condition code flags, error summary 
status flag, stack fault flag, and exception flags. The x87 FPU sets the flags in this register to show the results of 
operations. 

 

The contents of the x87 FPU status register (referred to as the x87 FPU status word) can be stored in memory using 
the FSTSW/FNSTSW, FSTENV/FNSTENV, FSAVE/FNSAVE, and FXSAVE instructions. It can also be stored in the AX 
register of the integer unit, using the FSTSW/FNSTSW instructions.

8.1.3.1  

Top of Stack (TOP) Pointer

A pointer to the x87 FPU data register that is currently at the top of the x87 FPU register stack is contained in bits 
11 through 13 of the x87 FPU status word. This pointer, which is commonly referred to as TOP (for top-of-stack), 
is a binary value from 0 to 7. See Section 8.1.2, “x87 FPU Data Registers,” for more information about the TOP 
pointer.

8.1.3.2  

Condition Code Flags

The four condition code flags (C0 through C3) indicate the results of floating-point comparison and arithmetic oper-
ations. Table 8-1 summarizes the manner in which the floating-point instructions set the condition code flags. 
These condition code bits are used principally for conditional branching and for storage of information used in 
exception handling (see Section 8.1.4, “Branching and Conditional Moves on Condition Codes”).
As shown in Table 8-1, the C1 condition code flag is used for a variety of functions. When both the IE and SF flags 
in the x87 FPU status word are set, indicating a stack overflow or underflow exception (#IS), the C1 flag distin-
guishes between overflow (C1 = 1) and underflow (C1 = 0). When the PE flag in the status word is set, indicating 
an inexact (rounded) result, the C1 flag is set to 1 if the last rounding by the instruction was upward. The FXAM 
instruction sets C1 to the sign of the value being examined.

Figure 8-4.  x87 FPU Status Word

FPU Busy

15

13

14

11 10 9 8 7 6 5 4 3 2 1 0

B

I

E

P

E

O

E

U

E

Z

E

D

E

TOP

Top of Stack Pointer

Exception Flags
   Precision
   Underflow
   Overflow
   Zero Divide
   Denormalized Operand
   Invalid Operation

Stack Fault

Error Summary Status

Condition
   Code

C

2

C

1

C

0

E
S

S
F

C

3