Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIPS Assembly Multiplication and Moving the Hi and Lo into Register

Tags:

assembly

mips

mult instruction can multiply two 32-bit integers which could give a 64-bit result. The higher significant 32 bits of the result (32 - 63) are saved in Hi and the lower bits (0 - 31) are saved in Lo. After the multiplication I can use mfhi and mflo to move the result to registers. But it is obviously not possible to write the 64-bit number into a 32-bit register. How can I store the result back into registers and use it? Should I save each part in a separate register and concatenate them?

like image 801
Infinity Avatar asked Oct 31 '22 20:10

Infinity


1 Answers

You are correct that you save by both mfhi and mflo to registers separately. You just have to check if your product takes both registers (when Hi is NOT zero) then you take that into account and process both.

like image 155
Ruslan Gerasimov Avatar answered Nov 15 '22 12:11

Ruslan Gerasimov