如何在MIPS中将两个数字相乘,从而得出大于32位的乘积? [英] How to multiply two numbers in MIPS which gives product that is larger than 32bits?

查看:275
本文介绍了如何在MIPS中将两个数字相乘,从而得出大于32位的乘积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我的任务是在MIPS中将两个32位数字相乘,然后生成64位的输出.据我了解,最低有效的32位将保存在"lo"寄存器中,其余的将保存在"hi"寄存器中.

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.

当我将100000和200000相乘时,在"lo"寄存器中得到a817c800,在"hi"寄存器中得到4

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

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

推荐答案

当我将100000和200000相乘时,在"lo"寄存器中得到a817c800,在"hi"寄存器中得到4

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

正确.

由于结果为64位宽,并且您使用的是32位MIPS CPU,因此需要两个寄存器来存储结果.

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

在您的代码中,高32位在s1中,低32位在s0中.因此,两个寄存器s1s0表示64位值4a817c800(十六进制),即20000000000(十进制).这是正确的结果.

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.

您的下一个问题可能是如何使用qtspim打印出64位数字.不幸的是,我没有使用MIPS模拟器的经验(仅在真正的MIPS CPU上),所以我完全不知道这是不可能的.

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.

这篇关于如何在MIPS中将两个数字相乘,从而得出大于32位的乘积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆