Intel 80286, 80287 manual Fstsw AX/FNSTSW AX

Models: 80287 80286

1 515
Download 515 pages 45.04 Kb
Page 409
Image 409

PROGRAMMING NUMERIC APPLICATIONS

FSTSWIFNSTSW destination

FSTSW/FNSTCW (store status word) writes the current value of the 80287 status word to the desti- nation operand in memory. The instruction is used to

Implement conditional branching following a comparison or FPREM instruction (FSTSW)

Poll the 80287 to determine if it is busy (FNSTSW)

Invoke exception handlers in environments that do not use interrupts (FSTSW).

FSTSW checks for unmasked numeric exceptions, FNSTSW does not.

FSTSW AX/FNSTSW AX

FSTSW AX/FNSTSW AX (store status word to AX) is a special 80287 instruction that writes the current value of the 80287 status word directly into the 80286 AX register. This instruction optimizes conditional branching in numeric programs, where the 80286 CPU must test the condition of various NPX status bits. The waited form checks for unmasked numeric exceptions, the non-waited for does not.

When this instruction is executed, the 80286 AX register is updated with the NPX status word before the CPU executes any further instructions. In this way, the 80286 can immediately test the NPX status word without any WAIT or other synchronization instructions required.

FCLEX/FNCLEX

FCLEX/FNCLEX (clear exceptions) clears all exception flags, the error status flag and the busy flag in the status word. As a consequence, the 80287's ERROR line goes inactive. FCLEX checks for unmasked numeric exceptions, FNCLEX does not.

FSAVE/FNSAVE destination

FSAVE/FNSAVE (save state) writes the full 80287 state-environment plus register stack-to the memory location defined by the destination operand. Figure 2-1 shows the layout of the 94-byte save area; typically the instruction will be coded to save this image on the CPU stack. FNSAVE delays its execution until all NPX activity completes normally. Thus, the save image reflects the state of the NPX following the completion of any running instruction. After writing the state image to memory, FSAVE/FNSAVE initializes the 80287 as if FINIT/FNINIT had been executed.

FSAVE/FNSAVE is useful whenever a program wants to save the current state of the NPX and initialize it for a new routine. Three examples are

An operating system needs to perform a context switch (suspend the task that had been running and give control to a new task).

An exception handler needs to use the 80287.

An application task wants to pass a "clean" 80287 to a subroutine.

FSAVE checks for unmasked numeric errors before executing, FNSAVE does not. An FWAIT should be executed before CPU interrupts are enabled or any subsequent 80287 instruction is executed. Other CPU instructions may be executed between the FNSAVE/FSAVE and the FWAIT.

2-17

Page 409
Image 409
Intel 80286, 80287 manual Fstsw AX/FNSTSW AX