moisu
moisu

Reputation: 343

MIPS32 64-bit Number Divided by 32-bit Number

I am trying to figure out how to divide a 64-bit number (say the higher 32 bits are stored in $s3 and the lower 32 bits are stored in $s4) by a 32-bit number (say it is stored in $s5).

I know the div instruction can only take 32-bit values as inputs and that the HI register stores the 32-bit remainder and the LO register stores the 32-bit quotient.

Knowing this, would I need to do a combination of:

div $s3, $s5
mfhi $t0
mflo $t1
div $s4, $s5
mfhi $t2
mflo $t3

But then I am not sure what I need to do with the quotient and remainders of those calculations to get the entire result.

Upvotes: 0

Views: 226

Answers (1)

user10316011
user10316011

Reputation:

http://x86asm.net/articles/working-with-big-numbers-using-x86-instructions/#Division <- example how similar division is done on Intel. They use the remainder from the higher division as the high 32 bits of the next lower number-to-be-divided. Of course if you had an Intel-like div-64-by-32 instruction, you would not be asking this question. If the number you are dividing by is small enough, you could do the same in 16-bit steps. Otherwise you may need to implement your own division the hard way.

Upvotes: 1

Related Questions