
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
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
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.