Reputation: 1191
I am new to assembly language, and I am really confused over multiplying.
I was reading the quick tutorial here (dead link, web archive here)
It says after I use mult $t0, $t1
the results are stored in Hi and Lo, I understand these are special registers for mult
and div
, but how do I access them?
Lets say I do mult $t0, $t1
where $t0
and $t1
are both 2. How do I get the result? (4)
Upvotes: 5
Views: 6275
Reputation: 2548
MULT $t1, $t2 #multiplies 2 registers
MFLO $t3 #stores the product in this register
MFHI $t4 #stores the remainder
Because there is no modulus command, you can do the multiplication and take whatever result is in MFHI to be the result. For division, it also uses MFLO and MFHI for the result of the operation.
Upvotes: 0
Reputation: 1
for E.g:
.globl main
main:
li $t0,3
li $t1,2
mult $t0,$t1
The mult condition multiplies 2 signed 32 bits and form 64 bit result. To access that first store the values in registers using commands. This stores HI, LO values to general purpose registers.
mfhi $t2
mflo $t3
and then print these values using printing statement:
move $a0,$t2
li $v0,1
syscall
move $a0,$t3
li $v0,1
syscall
to get the output on console.
To get the result of multiplication you can use another command i.e.
mul $t2,$t0,$t1
where you store the product of values in Register 1 and Register 0 in Register 2.This however corrupts HI and LO.
Upvotes: 0