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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.