我如何乘两个整数,其中一个比MIPS 32位大? [英] How do I multiply two integers where one is larger than 32 bits in MIPS?
本文介绍了我如何乘两个整数,其中一个比MIPS 32位大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下子例程用于查找$ A0至$ A1的力量。它工作正常的小整数,但我想它为像1000 ^ 6工作。我在想,如果我保存喜寄存器为$ V1乘法。
所以我想我的主要问题是:我如何乘两个整数,其中一个是大于32位的?
POW:
李$ V0,1
pow_loop:
BLE $ A1,$零,pow_conclude
MULT $ V0,$ A0
MFLO $ V0
阿迪$ A1,$ A1,-1
Ĵpow_loop
pow_conclude:
JR $ RA
解决方案
阅读本杰克逊的回答后,我写了这一点,并与MARS检查了。
POW:
李$ V0,1
李$ V1,0
pow_loop:
BLE $ A1,$零,pow_conclude
MULT $ V1,$ A0
MFLO $ V1
MULT $ V0,$ A0
MFLO $ V0
MFHI $ T0
加$ V1,V1 $,$ T0
阿迪$ A1,$ A1,-1
Ĵpow_loop
pow_conclude:
JR $ RA
I have the following subroutine that is used to find $a0 to the power of $a1. It works fine for small integers, but I want it to work for something like 1000^6. I was thinking that if I store the hi register for the multiplication in $v1.
So I guess my main question is, "How do I multiply two integers where one is larger than 32 bits?"
pow:
li $v0, 1
pow_loop:
ble $a1, $zero, pow_conclude
mult $v0, $a0
mflo $v0
addi $a1, $a1, -1
j pow_loop
pow_conclude:
jr $ra
解决方案
After reading Ben Jackson's answer, I wrote this and checked it with MARS.
pow:
li $v0, 1
li $v1, 0
pow_loop:
ble $a1, $zero, pow_conclude
mult $v1, $a0
mflo $v1
mult $v0, $a0
mflo $v0
mfhi $t0
add $v1, $v1, $t0
addi $a1, $a1, -1
j pow_loop
pow_conclude:
jr $ra
这篇关于我如何乘两个整数,其中一个比MIPS 32位大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文