Volume 5 64-Bit Media and x87 Floating-Point Instructions (794099), страница 41
Текст из файла (страница 41)
3.08—July 2007FSTENV(FNSTENV)Floating-Point Store EnvironmentStores the current x87 environment to memory starting at the specified address, and then masks allfloating-point exceptions. The x87 environment consists of the x87 control, status, and tag wordregisters, the last non-control x87 instruction pointer, the last x87 data pointer, and the opcode of thelast completed non-control x87 instruction.The FSTENV instruction takes a memory operand that specifies the start of either a 14-byte or 28-bytearea in memory. The 14-byte operand is required for a 16-bit operand-size; the 28-byte memory area isrequired for both 32-bit and 64-bit operand sizes. The layout of the saved x87 environment within thespecified memory area depends on whether the processor is operating in protected or real mode.
See“Media and x87 Processor State” in Volume 2 for details on how this instruction stores the x87environment in memory. (Because FLDENV/FSTENV do not save the full 64-bit data and instructionpointers, 64-bit applications should use FXSAVE/FXRSTOR, rather than FLDENV/FSTENV.)The FNSTENV instruction does not check for possible floating-point exceptions before storing theenvironment.Assemblers usually provide an FSTENV macro that expands into the instruction sequenceWAITFNSTENV destination; Opcode 9B; Opcode D9 /6The WAIT (9Bh) instruction checks for pending x87 exceptions and calls an exception handler ifnecessary. The FNSTENV instruction then stores the state of the x87 environment to the specifieddestination.Exception handlers often use these instructions because they provide access to the x87 instruction anddata pointers.
An exception handler typically saves the environment on the stack. The instructionsmask all floating-point exceptions after saving the environment to prevent those exceptions frominterrupting the exception handler.MnemonicOpcodeDescriptionFSTENVmem14/28env9B D9 /6Perform a WAIT (9B) to check for pending floating-pointexceptions, then copy the x87 environment to mem14/28envand mask the floating-point exceptions.FNSTENVmem14/28envD9 /6Copy the x87 environment to mem14/28env withoutchecking for pending floating-point exceptions, and mask theexceptions.Related InstructionsFLDENV, FSTSW, FNSTSW, FSTCW, FNSTCW306FSTENV (FNSTENV)Instruction Reference26569—Rev. 3.08—July 2007AMD64 TechnologyrFLAGS AffectedNonex87 Condition Codex87 Condition CodeValueC0UC1UC2UC3UDescriptionNote: A flag set to 1 or cleared to 0 is M (modified).
Unaffected flags are blank. Undefined flags are U.ExceptionsVirtual8086 ProtectedExceptionRealDevice not available,#NMXXXThe emulate bit (EM) or the task switch bit (TS) of thecontrol register (CR0) was set to 1.Stack, #SSXXXA memory address exceeded the stack segment limit orwas non-canonical.XXXA memory address exceeded a data segment limit or wasnon-canonical.XThe destination operand was in a nonwritable segment.XA null data segment was used to reference memory.General protection,#GPCause of ExceptionPage fault, #PFXXA page fault resulted from the execution of the instruction.Alignment check,#ACXXAn unaligned memory reference was performed whilealignment checking was enabled.Instruction ReferenceFSTENV (FNSTENV)307AMD64 Technology26569—Rev.
3.08—July 2007FSTSW(FNSTSW)Floating-Point Store Status WordStores the current state of the x87 status word register in either the AX register or a specified two-bytememory location. The image of the status word placed in the AX register always reflects the resultafter the execution of the previous x87 instruction.The AX form of the instruction is useful for performing conditional branching operations based on thevalues of x87 condition flags.The FNSTSW instruction does not check for possible floating-point exceptions before storing the x87status word.Assemblers usually provide an FSTSW macro that expands into the instruction sequence:WAITFNSTSW destination; Opcode 9B; Opcode DD /7 or DF E0The WAIT (9Bh) instruction checks for pending x87 exceptions and calls an exception handler ifnecessary.
The FNSTSW instruction then stores the state of the x87 status register to the desireddestination.MnemonicOpcodeDescriptionFSTSW AX9B DF E0Perform a WAIT (9B) to check for pending floating-pointexceptions, then copy the x87 status word to the AX register.FSTSW mem2env9B DD /7Perform a WAIT (9B) to check for pending floating-pointexceptions, then copy the x87 status word to mem12byte.FNSTSW AXDF E0Copy the x87 status word to the AX register withoutchecking for pending floating-point exceptions.FNSTSW mem2envDD /7Copy the x87 status word to mem12byte without checkingfor pending floating-point exceptions.Related InstructionsFSTCW, FNSTCW, FSTENV, FNSTENVrFLAGS AffectedNone308FSTSW (FNSTSW)Instruction Reference26569—Rev.
3.08—July 2007AMD64 Technologyx87 Condition Codex87 Condition CodeValueC0UC1UC2UC3UDescriptionNote: A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefined flags are U.ExceptionsVirtual8086 ProtectedExceptionRealDevice not available,#NMXXXThe emulate bit (EM) or the task switch bit (TS) of thecontrol register (CR0) was set to 1.Stack, #SSXXXA memory address exceeded the stack segment limit orwas non-canonical.XXXA memory address exceeded a data segment limit or wasnon-canonical.XThe destination operand was in a nonwritable segment.XA null data segment was used to reference memory.General protection,#GPCause of ExceptionPage fault, #PFXXA page fault resulted from the execution of the instruction.Alignment check,#ACXXAn unaligned memory reference was performed whilealignment checking was enabled.Instruction ReferenceFSTSW (FNSTSW)309AMD64 Technology26569—Rev.
3.08—July 2007FSUBFSUBPFISUBFloating-Point SubtractSubtracts the value in a floating-point register or memory location from the value in another registerand stores the result in that register.If no operands are specified, the instruction subtracts the value in ST(0) from that in ST(1) and storesthe result in ST(1).If one operand is specified, it subtracts a floating-point or integer value in memory from the contents ofST(0) and stores the result in ST(0).If two operands are specified, it subtracts the value in ST(0) from the value in another floating-pointregister or vice versa.The FSUBP instruction pops the x87 register stack after performing the subtraction.The no-operand version of the instruction always pops the register stack. In some assemblers, themnemonic for this instruction is FSUB rather than FSUBP.The FISUB instruction converts a signed integer value to double-extended-precision format beforeperforming the subtraction.MnemonicOpcodeDescriptionFSUB ST(0),ST(i)D8 E0+iReplace ST(0) with ST(0) – ST(i).FSUB ST(i),ST(0)DC E8+iReplace ST(i) with ST(i) – ST(0).FSUB mem32realD8 /4Replace ST(0) with ST(0) – mem32real.FSUB mem64realDC /4Replace ST(0) with ST(0) – mem64real.FSUBPDE E9Replace ST(1) with ST(1) – ST(0) and pop the x87 registerstack.FSUBP ST(i),ST(0)DE E8+iReplace ST(i) with ST(i) – ST(0), and pop the x87 registerstack.FISUB mem16intDE /4Replace ST(0) with ST(0) – mem16int.FISUB mem32intDA /4Replace ST(0) with ST(0) – mem32int.Related InstructionsFSUBRP, FISUBR, FSUBRrFLAGS AffectedNone310FSUBxInstruction Reference26569—Rev.
3.08—July 2007AMD64 Technologyx87 Condition Codex87 Condition CodeValueC0UDescription0No precision exception occurred.0x87 stack underflow, if an x87 register stack fault was detected.0Result was rounded down, if a precision exception was detected.1Result was rounded up, if a precision exception was detected.C1C2UC3UNote: A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.ExceptionsVirtual8086 ProtectedExceptionRealCause of ExceptionDevice not available,#NMXXXThe emulate bit (EM) or the task switch bit (TS) of thecontrol register (CR0) was set to 1.Stack, #SSXXXA memory address exceeded the stack segment limit orwas non-canonical.General protection,#GPXXXA memory address exceeded a data segment limit or wasnon-canonical.XA null data segment was used to reference memory.Page fault, #PFXXA page fault resulted from the execution of the instruction.Alignment check,#ACXXAn unaligned memory reference was performed whilealignment checking was enabled.XXAn unmasked x87 floating-point exception was pending.x87 floating-pointexception pending,#MFXx87 Floating-Point Exception Generated, #MFXXXA source operand was an SNaN value or an unsupportedformat.XXX+infinity was subtracted from +infinity.XXX–infinity was subtracted from –infinity.Invalid-operationexception (IE) withstack fault (SF)XXXAn x87 stack underflow occurred.Denormalizedoperand exception(DE)XXXA source operand was a denormal value.Overflow exception(OE)XXXA rounded result was too large to fit into the format of thedestination operand.Invalid-operationexception (IE)Instruction ReferenceFSUBx311AMD64 Technology26569—Rev.
3.08—July 2007Virtual8086 ProtectedExceptionRealUnderflow exception(UE)XXXA rounded result was too small to fit into the format of thedestination operand.Precision exception(PE)XXXA result could not be represented exactly in the destinationformat.312Cause of ExceptionFSUBxInstruction Reference26569—Rev. 3.08—July 2007FSUBRFSUBRPFISUBRAMD64 TechnologyFloating-Point Subtract ReverseSubtracts the value in a floating-point register from the value in another register or a memory location,and stores the result in the first specified register.