【发布时间】:2015-04-09 19:50:59
【问题描述】:
我试图在 MIPS 中将两个 32 位数字相乘。我这里有一些使用 mult 操作的代码。我使用 mfhi 和 mflo 操作从 mult 获取这两个部分,但我不确定如何正确地将它们组合在一起。例如,我让他们分别打印出操作。
我一直使用的输入数字是: 1143330295和999999223
我从这个程序得到的输出(显然需要一些工作)是: 266202121 -1483441327
正确的输出应该是 1143329406632360785,或者如果这样更容易的话,我可以用二进制输出。
这段代码来自我正在处理的一个更大的项目,它必须使用移位和相加算法将两个 32 位数字相乘,而不使用 mult 函数。我只是想首先代表 64 位数字。感谢您的任何建议/意见。
.data
getA: .asciiz "Please enter the first number(multiplicand): "
getB: .asciiz "Please enter the second number(multiplier): "
space: .asciiz " "
promptStart: .asciiz "This program multiplies two numbers. "
mipMult: .asciiz "The product, using MIPs mult is: "
endLine: .asciiz "\n"
.text
main:
li $v0,4
la $a0,promptStart
syscall
li $v0,4
la $a0,endLine
syscall
#prompt for multiplicand
li $v0,4
la $a0,getA
syscall
#acquire multiplicand
li $v0,5
syscall
move $s0,$v0
move $s5,$s0
#prompt for multiplier
li $v0,4
la $a0,getB
syscall
#acquire multiplier
li $v0,5
syscall
move $s1,$v0
move $s6,$s1 # copy
mult $s5, $s6
mfhi $t0
mflo $t1
li $v0,4
la $a0,mipMult
syscall
# print out the result (This is obviously not correct, I need some help)
li $v0,1
move $a0,$t0
syscall
li $v0,4
la $a0,space
syscall
# print out the result
li $v0,1
move $a0,$t1
syscall
# print the line feed
li $v0,4
la $a0,endLine
syscall
li $v0,10
syscall # exit program
【问题讨论】: