Hello,
I am writing certain code in MIPS and I've come to the point where the requirement is to store the result, temporarily, in HI
and LO
special registers (both are 8 bytes wide). These instructions are at my disposal:
divu s,t lo <-- s div t ; hi <-- s mod t
multu s,t hi / lo < -- s * t ;
So, divu
stores result of division in LO
and remainder in HI
, while multu
stores result of multiplication in LO
(lower 8 bytes) and HI
(higher 8 bytes).
Later, to retrieve result from HI
and LO
registers, I can:
mfhi $v0
mflo $v1
I already figured out how to store result of a calculation in LO
:
ori $v0,$0,1 # Store result from $a0 into LO
divu $a0,$v0
- the
divu
stores result of the division in LO, so I just divide result by 1 to get it there.
However, storing in HI
is more complicated. One way would be to force multu
instruction to shift the value by 32 bits (8 bytes):
multu $a0,0x80000000 # Shift $a0 by 32 bits and store into HI/LO
But, the result is that the value in HI
is 1 bit right of where it should be (so if my value is 0100 1000
then HI
will contain 0010 0100
).
Does anyone know how to store something in HI
register?