I'm really having a difficult time figuring out how to approach this problem. I get that I want to take the binary representation of both the integer and fraction, combine them for the mantissa, and assign the sign bit to the beginning, but I don't know how to actually implement it in MIPS.
Can anyone help me at least get started?
Assume that your MIPS hardware does not have floating-point registers and floating-point ALU. If you want to perform floating point addition, you will have to use MIPS integer instructions that use the integer registers ($0 - $31) and the integer ALU to get the job done. In this assignment question, you will write MIPS code, using integer instructions and integer registers only, to implement a procedure to add two float-point numbers and to write a main function to call the procedure.
Write a MIPS procedure toFloat to put a floating-point number into IEEE single-precision format. The procedure takes three integers as input: $a0, $a1, $a2, which represents a floating-point number in this way: If $a0 contains 0, the floating-point number is positive, else if $a0 contains 1, the floating-point number is negative. The number stored in register $a1 is the integer part of the floating-point number, and the number stored in register $a2 is the fraction part of the floating-point number. For example, to present the floating-point number -5.25, the three input registers should contain these numbers: $a0 = 1, $a1 = 5, and $a2 = 25. For the fraction part, you can use the div rs rt instruction to divide 25 by 100. The fraction will be stored in the HI register, and you can use the mfhi instruction to retrieve the fraction. The procedure will return v0, which contains the IEEE single-precision pattern corresponding to the floating-point number represented by the three input numbers. Once you have this procedure, you can use it to convert the input numbers 2.5 and 7.5 into their IEEE single-precision format.
Write a MIPS procedure printFloat to print a number that is in the IEEE single-precision format. The input of the procedure is in $a0, which is a number in the IEEE single-precision format. The procedure will simply print the bit pattern stored in $a0. You can use a loop to print each bit. Once you have this procedure, you can use it to print the input number 2.5 and 7.5 in their floating-point format.
Write a MIPS program to implement the main function to call your procedures. In this program, you will call
toFloat(0, 2, 5) to generate the float-point format for 2.5;
toFloat(0, 7, 5) to generate the float-point format for 7.5;
printFloat to print 2.5
printFloat to print 7.5
Here's the code that I have so far: