我试图在MIPS程序集中乘以两个IEEE 754数字而不使用浮点运算。在MIPS中乘以两个IEEE 754浮点数
我获得存储在$ A0两个浮点数和我有尾数部分我觉得麻烦$ 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
。根据我的逻辑,我将乘以小数部分,然后摆脱领先1.例如1.011 * 1.010 = 1.10111,我会切断领先1导致10111作为我的新尾数。我这样做只是删除小数点,所以:1011 * 1010 = 110111和切断领先的1导致10111.
然而,多功能是给出了非常奇怪的结果,我不知道为什么。任何人都可以看到我的逻辑错误?
_“非常奇怪的结果”_不是一个很好的问题描述。输入和输出是什么(预期和实际)?由于您声称问题出现在'mul'中,请显示该指令的值。PS:你知道尾数是24位,所以你需要64位乘法? – Jester
提示:产品符号是两个操作数符号的异或运算 – Nayuki
一般而言,位级浮点操作相当困难,因为您需要处理归一化,上溢,下溢,低于正常,无穷大和NaN。我期望一个全功能的乘法程序能够像你所显示的那样获得3倍的代码 – Nayuki