What is the pseudo instruction for division in MIPS? Like there is a pseudo instruction of multiplication is MIPS "mul" which makes the life a little bit easier. I am using QT Spim.
Regards
To perform integer division you can use div $t1, $t2, $t3 which will set $t1 to the integer division of $t2/$t3, or div $t1, $t2, imm where imm is an immediate.
Likewise, to compute the remainder of integer division, you can use rem $t1, $t2, $t3 or rem $t1, $t2, imm
These pseudoinstructions will basically do a div $t1, $t2 which stores the results in LO and HI special registers (for quotient and remainder) and then move those values to the target register by means of mfhi and mflo.
To perform floating point division you need to use floating point registers $f0 to $f31.
Once you have your floating point numbers stored in some of these registers (properly encoded as floating point numbers, e.g. in $f1 and $f2) you issue a div.s $f0, $f1, $f2 instruction to get into $f0 the result of $f1/$f2.
Now, to get the remainder you can subtract the result of the division with the truncation of the result.
For example:
li $a1, 20
mtc1 $a1, $f1
cvt.s.w $f1, $f1 # $f1 = 20
li $a1, 7
mtc1 $a1, $f2
cvt.s.w $f2, $f2 # $f2 = 7
div.s $f0, $f1, $f2 # $f0 = 20/7
trunc.w.s $f3, $f0
cvt.s.w $f3, $f3 # $f3 = trunc(20/7)
sub.s $f4, $f0, $f3 # $f4 = remainder of 20/7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With