How to multiply two numbers in MIPS which gives product that is larger than 32bits?

只谈情不闲聊 提交于 2019-12-25 01:34:16

问题


Actually, my task is to multiply two 32bits number in MIPS which then generate the output of 64bits. Least significant 32bits are to be saved in 'lo' register and the remaining in 'hi' register to my understanding.

When I multiply 100000 and 200000 I get a817c800 in 'lo' register and 4 in 'hi' register

mult $t1, $t2 
    mflo $s0
    mfhi $s1 


回答1:


When I multiply 100000 and 200000 I get a817c800 in 'lo' register and 4 in 'hi' register

Correct.

Because the result is 64 bits wide and you are using a 32-bit MIPS CPU, you need two registers to store the result.

In your code, the high 32 bits are in s1 and the low 32 bits are in s0. So the two registers s1 and s0 represent the 64-bit value 4a817c800 (hexadecimal) which is 20000000000 (decimal). And this is the correct result.

Your next question might be how you can print out a 64-bit number with qtspim. Unfortunately, I have no experiences with MIPS simulators (only with real MIPS CPUs), so I don't know if this is possible at all.



来源:https://stackoverflow.com/questions/55441144/how-to-multiply-two-numbers-in-mips-which-gives-product-that-is-larger-than-32bi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!