首页 文章

在MIPS中乘以IEEE-754浮点数

提问于
浏览
0

我必须将浮点数(使用IEEE 754格式)乘以2而不使用浮点指令 .

我遇到的麻烦是在乘法后修复指数部分 .

这就是我所拥有的 .

假设单精度浮点数在寄存器中 $t0

sll    $t1, $t0, 9        t1 holds fraction part
sll    $t2, $t0, 1
srl    $t2, $t2, 24       t2 holds exponent part
srl    $t3, $t0, 31       t3 holds the sign bit

sll    $t1, $t1, 1        multiply fraction by 2
#do something to exponent in $t2 ##

#now put it all back together
sll    $t3, $t3, 31       put sign bit in the 31nd bit position
sll    $t2, $t2, 23       put exponent in the 30-23 bit positions
srl    $t1, $t1, 9        put fraction in the 22-0 bit positions

or     $t4, $t1, $t2
or     $t4, $t4, $t3      t4 now holds the value of t0*2

如果我将分数乘以2,我不明白指数会如何变化 .

1 回答

  • 1

    你这里做错了

    sll    $t1, $t1, 1        multiply fraction by 2
    

    IEEE-754浮点数的值基于此公式

    (-1)^sign * 1.mantissa * 2^exponent
    

    当乘以2时,只有小数点向右移动,所有位保持不变,因此尾数部分与之前相同 . 要乘以2,将指数增加1,而不是将其乘以2,因为 2*2^exp = 2^(exp+1)

    所以你应该这样做

    addi $t2, $t2, 1
    

相关问题