A good tutorial for the x87 FPU is beyond the scope of Stackoverflow but I can recommend the one on MASM forums. Another good source is the Intel Instruction Set Reference. In particular most functions starting with Show
In general you can't just add a floating point value to an integer. They are two different representations. What you can do is convert the integer to a floating point value and then do floating point computations with it. In particular the instructions that start with There are many ways to skin a cat, but if you review the FPU tutorial linked to above you may realize that one simplistic way is to do this:
Rather than using global variables to store values in main memory temporarily I used the stack space we reserve as a temporary staging area to load/operate with the x87 FPU. If you are on a CPU that supports the SSE2 instruction set (This includes any X86-64 processor in 32-bit mode) then you have other options. One is to use the SIMD instructions and registers to do 32-bit and 64-bit floating point operations. Using the instruction set reference you find some useful instructions like:
A Scalar Single-Precision FP value is a 32-bit float. A Scalar Double-Precision is a 64-bit double. The There's another
Description ¶Converts the signed-integer source operand into double extended-precision floating-point format and pushes the value onto the FPU register stack. The source operand can be a word, doubleword, or quadword integer. It is loaded without rounding errors. The sign of the source operand is preserved. This instruction’s operation is the same in non-64-bit modes and 64-bit mode. Operation ¶TOP := TOP − 1; ST(0) := ConvertToDoubleExtendedPrecisionFP(SRC); FPU Flags Affected ¶
Floating-Point Exceptions ¶
Protected Mode Exceptions ¶
Real-Address Mode Exceptions ¶
Virtual-8086 Mode Exceptions ¶
Compatibility Mode Exceptions ¶Same exceptions as in protected mode. 64-Bit Mode Exceptions ¶
Which instruction is used to initialize the FPU?Which instruction is used to initialize the FPU? The IA-32 FPU FLD instruction can only load in REAL10 floats, not REAL4 or REAL8. The IA-32 FPU is directly connected to the ALU via internal bus.
What instruction would I use to save the current value of the flags register?What instruction would I use to save the current value of the flags register? Mechanically speaking, the CALL instruction pushes its return address on the stack and copies the called procedure's address into the instruction pointer.
|