| Multiplication, Division | |||||||||||||
| Result of multiplying 2 32-bit numbers can be up to 64 bits | |||||||||||||
| Instructions | Semantics | Type | |||||||||||
| mult $rs, $rt | (HI, LO) = R[s] * R[t] | signed | R | ||||||||||
| multu $rs, $rt | unsigned | R | |||||||||||
| HI: high 32 bits | |||||||||||||
| LO: low 32 bits | |||||||||||||
| Note that $rd does not appear (set to 00000 in instruction) | |||||||||||||
| Division | |||||||||||||
| div $rs, $rt | LO = R[s] / R[t] | signed | R | ||||||||||
| divu $rs, $rt | HI = R[s] % R[t] | unsigned | R | ||||||||||
| LO: quotient | |||||||||||||
| HI: remainder | |||||||||||||
| To access HI, LO: | |||||||||||||
| mfhi $rd | R[d] = HI | R | |||||||||||
| mflo $rd | R[d] = LO | R | |||||||||||
| Note that $rs, $rt both 00000 | |||||||||||||
| Multiplication, division are slow: results not available for 2 instructions afterward. | |||||||||||||
| How can we ensure that? | |||||||||||||
| nop: "no operation" | |||||||||||||
| sll $0, $0, 0 | # shift reg 0 left 0 bits; store result in $0 | ||||||||||||
| Machine code: all 0's | |||||||||||||