Of course. The various bit manipultion instructions could be used for this.
Early microprocessors had no direct support for floating point and such manipulation was common.
Instruction | Operation |
---|---|
cvt.s.w fs, fw |
Convert the 32-bit integer in float register |
cvt.w.s fw, fs |
Convert the 32-bit float in register |
the "w" means 32-bit integer full word. | |
the "s" means 32-bit single precision. |
High level languages allow you to write statments like this:
float val = 1.0 + 1;
The operands are of mixed types. The statement compiles into machine operations that convert the integer into floating point and perform a floating point addition. Operations are always between data of the same type, even when that is not what the programmer wrote.
Rather than use bit manipulation instructions to convert an integer to floating point, MIPS (and QtSpim) has machine instructions that do this.
There are other instructions that convert between double precision and other data types, but we will not use them.
Is it possible to lose accuracy when converting a 32-bit integer into a 32-bit IEEE float?