divide float point number as integer in MIPS

1

I have loaded a float point double precission number in two $t registers, now I want to divide it by (-4) (not using fp instructions) and store it back into the $f register.

mfc1 $t0, $f0  #$f0 = 0x00000000
mfc1 $t1, $f1  #$f1 = 0x40240000
div $t1, $t1, -4
mfhi $t0 #move the remainder to $t0
mflo $t1 #move the quotient to $t1

mtc1 $t0, $f0
mtc1 $t1, $f1


# store the $f0 result in memory
# print X/(-4)


mov.d $f12, $f0
li $v0, 3
syscall

but this gives very unexpected result which is -2.231744757682269E231

any help will be appreciated.

assembly
floating-point
mips
cpu-registers
asked on Stack Overflow Mar 27, 2015 by Astronautilus

1 Answer

4

Obviously you can't just use an integer division. In the general case, you have to break up the numbers into their constituent parts, namely sign, mantissa and exponent, then implement division with integer arithmetic.

If you specifically want to divide by -4, you can use the fact that it is a power of 2, so you just need to flip the sign bit and subtract 2 from the exponent.

Maybe read about floating point representations.

answered on Stack Overflow Mar 27, 2015 by Jester

User contributions licensed under CC BY-SA 3.0