This is a MIPS Assembly language program, which i need in one day.
You will write a MIPS assembly language function that performs floating-point addition. To simplify the programming, we constrain the two rational numbers to be positive. For testing purposes, you are provided a program that calls your function with the two parameters in $a0 and $a1.
Your floating-point addition function is to be called by “jal flpadd”. A template is given at the end of this file. You need to implement the procedure flpadd by yourself.
The algorithm to implement in your code is given in Figure in the attached file called "230diagram". However, this algorithm can be simplified since your addition function only needs to handle positive numbers and does not need to detect overflow or underflow. Also, you need not perform rounding (step 4 in the figure) since it would be complicated and because truncation is also a valid option (although less accurate). This leaves only steps 1–3 in the boxes at the top of the figure for you to implement.
With careful thought, you will also realize that in step 3 your code will never actually need to perform a left shift, because of the constrraint that it only needs to handle positive numbers. Convince yourself that this is true before writing the code. (Think about the properties of the significands that get added in step 2 and the properties that follow for the resulting sum.)
It is important to note that the most significant bit of the significand is an implied 1. After extracting the significands by using masking, your code can use an OR instruction to place the 1 into the proper bit of the significands before performing addition on them. Having this implied 1 bit in place in the significands will make the normalization step more straightforward. Later, when your code constructs the single floating-point result, your code will need to remove the implied 1 bit.
Since your code will add only positive numbers, the sign bits in the numbers being summed can be ignored. The sign bit of the resulting sum should be set to zero.
In summary, your algorithm will need to do the following:
1. Mask and shift down the two exponents.
2. Mask the two significands and append leading 1s.
3. Compare the exponents and subtract the smaller from the larger.
4. Set the exponent of the result to be the larger of the addend exponents.
5. Right shift the significand of the smaller number by the difference between exponents to align the two significands.
6. Sum the significands.
7. If the sum overflows [1, 2), right shift by 1 and increment the exponent by 1.
8. Strip the leading 1 from the sum significand.
9. Merge the sum significand and exponent
You should be able to implement the floating-point addition algorithm in under 50 lines of code.
# Two floating point numbers are stored at va and vb.
# You are expected to add these two floating point numbers
# using the algorithm in figure 3.6.
smask: .word 0x007FFFFF #significand mask
emask: .word 0x7F800000 #exponent mask
ibit: .word 0x00800000
obit: .word 0xff000000
va: .float 10.5, 10.55, 0.1 #Two float point data
vb: .float 20.5, 20.55, 0.2
addi $s0, $ra, 0 # store $ra
la $s1, va
la $s2, vb
add $s3, $0, $0
l.s $f0, 0($s1) # va --> $f0
l.s $f1, 0($s2) # vb --> $f1
mfc1 $a0, $f0 # $f0 --> $a0
mfc1 $a1, $f1 # $f1 --> $a1
jal flpadd # call flpadd
mtc1 $v0, $f12 # $v0 --> $f12
li $v0, 2
li $v0, 11
li $a0, ' '
addi $s1, $s1, 4
addi $s2, $s2, 4
addi $s3, $s3, 1 # Index increment by 1
bne $s3, 3, main_loop # exit conditition
move $ra, $s0 # $s0 --> $ra
li $v0, 10