在没有FPU的MIPS中添加64位IEEE 754数字

时间:2013-06-09 08:59:07

标签: mips ieee-754

我应该描述如何在不使用浮点单元的情况下在MIPS中实现两个双精度的加法。我知道如何用单精度IEEE 754做到这一点,但不知何故无法弄清楚如何在两个寄存器中进行整个转换业务(当规范化等)。

除了移位第一个寄存器,保存移位的位数,然后将相同数量的移位应用到第二个寄存器之外,还有其他方法吗?

1 个答案:

答案 0 :(得分:2)

如果您需要在MIPS32处理器上移动64位值,您可以执行以下操作:

# Left shift
# $t1:$t0 contains a 64-bit number
slt $t2,$t0,$0    # $t2 = ($t0 & 0x80000000) ? 1 : 0
sll $t0,$t0,1     # shift the low word left 1 bit
sll $t1,$t1,1     # shift the high word left 1 bit
or $t1,$t1,$t2    # add the carry from the low word to the high word

# Right shift
# $t1:$t0 contains a 64-bit number
sll $t2,$t1,31    # save the lsb of $t1 in the msb of $t2
srl $t1,$t1,1     # shift the high word right 1 bit
srl $t0,$t0,1     # shift the low word right 1 bit
or $t0,$t0,$t2    # add the carry from the high word to the low word

根据需要多次循环。