I am trying to multiply two IEEE 754 numbers in MIPS assembly without using floating point operations.
I have two floating point numbers stored in $a0 and $a1
multiply_fp: #$s0 = final sign bit, $s1 = final exponent, $s2 = final mantissa
#check the sign bit
srl $t1, $a0, 31 # leave just sign bit
srl $t2, $a1, 31 # leave just sign bit
bnez $t1, negative # check if sign bit is 1
bnez $t2, negative # check if sign bit is 1
positive:
addi $s0, $zero, 0 # set sign bit to 0
j exponent
negative:
addi $s0, $zero, 10000000000000000000000000000000 #set sign bit to 1
exponent:
andi $t1, $a0, 01111111100000000000000000000000 #get exponent bits from fp1
andi $t2, $a1, 01111111100000000000000000000000 #get exponent bits from fp2
srl $t1, $t1, 23 #move them all the way to the right
srl $t2, $t2, 23
add $s1, $t1, $t2 #add them together
addi $s1, $s1, -127 #subtract 127 from the sum
sll $s1, $s1, 23 #move them back to the right position
mantissa:
andi $t1, $a0, 00000000011111111111111111111111 #get the mantissa bits from fp1
andi $t2, $a1, 00000000011111111111111111111111 #get the mantissa bits from fp2
ori $t1, $t1, 00000000100000000000000000000000 #add a 1 at the msb
ori $t2, $t2, 00000000100000000000000000000000
mul $s2, $t1, $t2 #multiply the mantissas
andi $s2, 00000000011111111111111111111111 #cut the 1 back off
combine:
or $v0, $s0, $s1
or $v0, $v0, $s2
jr $ra
I am having trouble with the mantissa section I think. According to my logic I am to multiply the fraction portion and then get rid of leading 1. For example 1.011 * 1.010 = 1.10111 and I would cut off the leading 1 to result in 10111 as my new mantissa. I do this similarly by just removing the decimal points so: 1011 * 1010 = 110111 and cut off the leading 1 to result in 10111.
However the mul function is giving very odd results, and I'm not sure why. Can anyone see errors with my logic?