dnelle
dnelle

Reputation: 137

Adding 64 bit IEEE 754 numbers in MIPS w/o FPU

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?

Upvotes: 2

Views: 418

Answers (1)

Michael
Michael

Reputation: 58487

If you need to shift a 64-bit value on a MIPS32 processor you can do something like this:

# 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

Repeat in a loop as many times as necessary.

Upvotes: 2

Related Questions