2

I'm supposed to describe how I would implement the addition of two doubles in MIPS without using the floating point unit. I know how to do it with single precision IEEE 754, but somehow cannot figure out how to do the whole shifting business in two registers(when normalizing etc.).

Is there any other way than shifting the first register, saving the number of bits shifted, and then applying the same number of shifts to the second register?

4

1 回答 1

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

根据需要在循环中重复多次。

于 2013-06-10T13:34:35.900 回答