mul, mult, and multu Instructions
hi is 0 for multu or the replicated sign of lo for mult.
mfhi rd # move from himflo rd # move from lo
hi (lo) register to register rd.
The instruction mfhi can be used to transfer hi to a general-purpose register to test for overflow.
mul |
mulu (no overflow) |
mult |
|---|---|---|
.text li $t0, -11 mul $a0, $t0, 12 li $v0, 1 syscall |
.text li $t0, -11 mulu $a0, $t0, 12 li $v0, 1 syscall |
.text li $t0, -11 li $t1, 12 mult $t0, $t1 mflo $a0 li $v0, 1 syscall |
| Output | Output | Output |
multu (unsigned) |
mfhi |
mult |
.text li $t0, -2147483648 # smallest signed word is # 0x80000000 = -231 # = -2,147,483,648 li $t1, 2 multu $t0, $t1 mflo $a0 li $v0, 1 syscall |
.text li $t0, -2147483648 # smallest signed word is # 0x80000000 = -231 # = -2,147,483,648 li $t1, 2 multu $t0, $t1 mfhi $a0 li $v0, 1 syscall |
.text li $t0, -2147483648 # smallest signed word is # 0x80000000 = -231 # = -2,147,483,648 li $t1, 2 mult $t0, $t1 mfhi $a0 li $v0, 1 syscall |
| Output | Output | Output |
|
“Lost Time is never found again.” ― Benjamin Franklin, Poor Richard’s Almanack |