简体   繁体   中英

divide float point number as integer in MIPS

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM