RobertM041397
asked on
How convert integer to float?
I need assembly language to convert a 32 bit integer to a 32 bit float. My integer should always be consider positive and a fraction of 1 and right justified to the 6th digit beyond decimal point. For example:
integer = float
0 = .000000
1 = .000001
3872 = .003872
987654 = .987654
Also, if possible (not necessary for pts) can you explain the asm fpu instructions that are used to do such things.
integer = float
0 = .000000
1 = .000001
3872 = .003872
987654 = .987654
Also, if possible (not necessary for pts) can you explain the asm fpu instructions that are used to do such things.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FILD converts an integer to floating point and places it on the top of the floating point stack. It can handle a 16 bit, 32 bit, or 64 bit integer. This takes 3 clock cycles.
FDIV Divides the floating point value on the top of the stack by a specified floating point value. this takes about 39 clock cycles.
FSTP stores the floating point value that is on the top of the stack and then removes it from the stack. This takes 2 clock sycles.
FDIV Divides the floating point value on the top of the stack by a specified floating point value. this takes about 39 clock cycles.
FSTP stores the floating point value that is on the top of the stack and then removes it from the stack. This takes 2 clock sycles.
DSTFLT REAL4 ? ; Destination value to receive result.
DIVISOR REAL4 1000000. ; Used to divide integer value to make fractional
* * *
FILD SRCINT ; load the source integer and convert to float.
FDIV DIVISOR ; Divide by divisor.
FSTP DSTFLT ; Store the result and pop from floating point stack.