我应该描述如何在 MIPS 中实现两个 double 的加法而不使用浮点单元。我知道如何使用单精度 IEEE 754 来做到这一点,但不知何故无法弄清楚如何在两个寄存器中完成整个移位业务(当标准化等时)。
除了移位第一个寄存器,保存移位的位数,然后将相同的移位次数应用于第二个寄存器之外,还有其他方法吗?
最佳答案
如果您需要在 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
根据需要循环重复多次。
关于mips - 在不带 FPU 的 MIPS 中添加 64 位 IEEE 754 数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17008054/