mflo $8
The instructions mflo and
mfhi
are used to get the results of an integer divide.
For this example say that we wish to calculate
(y + x) / (y - x).
The argument x is in $8; y is in $9.
The quotient is to be placed in $10 and the remainder in $11.
Assume two's complement integers.
Here is the program.
Sadly, it has some holes:
## divEg.asm
##
## Program to calculate (y + x) / (y - x)
##
## Register Use:
## $8 x
## $9 y
## $10 x/y
## $11 x%y
.text
.globl main
main:
___ $8, $0, 8 # put x into $8
___ $9, $0, 36 # put y into $9
addu $10, $__, $__ # $10 <-- (y+x)
subu $11, $__, $__ # $11 <-- (y-x)
div $__, $__ # hilo <-- (y+x)/(y-x)
____ $10 # $10 <-- quotient
____ $11 # $11 <-- remainder
## End of file