mips 中的 for 循环不起作用?可能有什么问题?
我的MIPS循环代码不起作用。当我尝试运行此代码时,此显示我空白。可能是一个问题。
.data
.text
.globl main
main:
li $t0,0
for:
ble $t0,5,end //for (int i=0;i<=5;i++)
li $v0,1
move $a0,$t0
syscall
add $t0,$t0,1
j for
end:
li $v0,10
syscall
My Mips loop code not working. When i try to run this code this show me blank. what could be a problem.
.data
.text
.globl main
main:
li $t0,0
for:
ble $t0,5,end //for (int i=0;i<=5;i++)
li $v0,1
move $a0,$t0
syscall
add $t0,$t0,1
j for
end:
li $v0,10
syscall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当手动编译 C/伪代码时,特别是 if 语句和 for 循环的条件时,请记住,当条件不成立时,您通常希望“跳过”代码。在您的示例中,
您希望在不满足条件时跳过 for 主体。当 i 小于或等于 5 时,您必须进行分支,而不是在 i 大于 5 时进行分支。
然后您可以使用以下命令进行编译:
When hand compiling C/pseudo code, in particular if statements and the condition of for loops, remember that you usually want to jump "over" the code when the condition does not hold. In your example you have
so you want to jump over the for body when the condition is not met. Instead of branching when i is less than or equal to 5, you have to branch when its greater than 5.
You would then compile that for with this: