汇编语言作业遇到问题
我以为我正确地实现了 while 循环,但为什么我没有得到任何输出?
我的书没有多大帮助,而且我无法在网上找到资源。
##### The Data Segment #########
.data
strFirstNumber: .asciiz "Enter the first number (0-63): "
strSecondNumber: .asciiz "Enter the second number (0-63): "
strError: .asciiz "That number is not in the 0-63 range.\n\n"
#### The Text Segment ##########
.text
.globl main
main:
li $t2, 0
#First Number
li $10, 64
li $v0, 4
la $a0, strFirstNumber
syscall
li $v0, 5
syscall
blez $v0, in_error
bgeu $v0, $10, in_error
j DoneIf
in_error:
li $v0, 4
la $a0, strError
syscall
li $v0, 4
la $a0, strFirstNumber
syscall
li $v0, 5
syscall
bltz $v0, in_error
bgeu $v0, $10, in_error
DoneIf:
move $t0, $v0
#Second Number
li $v0, 4
la $a0, strSecondNumber
syscall
li $v0, 5
syscall
bltz $v0, in_error2
bgeu $v0, $10, in_error2
j DoneIf2
in_error2:
li $v0, 4
la $a0, strError
syscall
li $v0, 4
la $a0, strSecondNumber
syscall
li $v0, 5
syscall
blez $v0, in_error2
bgeu $v0, $10, in_error2
DoneIf2:
move $t1, $v0
Loop:
beq $t2, $t0, Exit
add $t3, $t1, $t1
add $t2, $t2, 1
j Loop # go to Loop
Exit:
li $v0, 1
add $a0, $0, $t3
syscall
jr $31
I thought I correctly implemented a while loop, but why am I not getting any output?
My book isn't that great of a help, and I haven't been able to find a resource online.
##### The Data Segment #########
.data
strFirstNumber: .asciiz "Enter the first number (0-63): "
strSecondNumber: .asciiz "Enter the second number (0-63): "
strError: .asciiz "That number is not in the 0-63 range.\n\n"
#### The Text Segment ##########
.text
.globl main
main:
li $t2, 0
#First Number
li $10, 64
li $v0, 4
la $a0, strFirstNumber
syscall
li $v0, 5
syscall
blez $v0, in_error
bgeu $v0, $10, in_error
j DoneIf
in_error:
li $v0, 4
la $a0, strError
syscall
li $v0, 4
la $a0, strFirstNumber
syscall
li $v0, 5
syscall
bltz $v0, in_error
bgeu $v0, $10, in_error
DoneIf:
move $t0, $v0
#Second Number
li $v0, 4
la $a0, strSecondNumber
syscall
li $v0, 5
syscall
bltz $v0, in_error2
bgeu $v0, $10, in_error2
j DoneIf2
in_error2:
li $v0, 4
la $a0, strError
syscall
li $v0, 4
la $a0, strSecondNumber
syscall
li $v0, 5
syscall
blez $v0, in_error2
bgeu $v0, $10, in_error2
DoneIf2:
move $t1, $v0
Loop:
beq $t2, $t0, Exit
add $t3, $t1, $t1
add $t2, $t2, 1
j Loop # go to Loop
Exit:
li $v0, 1
add $a0, $0, $t3
syscall
jr $31
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几乎不可能说出哪里出了问题:
$t
寄存器来存储值。这很糟糕,因为 MIPS 将它们定义为暂存寄存器。使用$s0
到$s7
,如果您正确输入了两个数字,则您的代码必须运行到循环中。同样,考虑到系统调用可能会破坏寄存器,它可能会运行很长一段时间。
首先尝试更改寄存器分配,然后删除不会更改
$t3
计算结果的循环。并可能检查您的打印系统调用是否正常工作。It's nearly impossible to say what's wrong:
$t
registers to store value. This is bad because MIPS define them as scratch regiters. Use$s0
to$s7
insteadBTW, if you correctly entered both numbers, your code must run into the loop. Again, given that syscalls probably trashed registers, it may run for a ... long ... time.
Try to change register allocation first, then remove the loop that does not change the result computed into
$t3
. And possibly check that your syscall to print work correctly.这是因为你没有在程序中描述“syscall”中发生了什么过程,似乎没有真正的输出结果。
It is because you haven't described in the program what process happens in 'syscall' There seems to be no real output result.