MIPS 汇编中的 For 循环
我在让我的处理器正确模拟时遇到问题,我想我已经将范围缩小到我提供的程序。
1. li $R1, 0
2. li $R2, 0x100
3. li $R6, 1
4. li $R8, 0
5. li $R9, 20
6. lw $R3, 0($R1)
7. lw $R4, 4($R1)
8. add $R5, $R3, $R4
9. srlv $R5, $R5, $R6
10. sw $R5, 0($R2)
11. addi $R1, $R1, 4
12. addi $R2, $R2, 4
13. addi $R8, $R8, 1
14. slt $R7, $R8, $R9
15. bne $R7, $zero, -9
它应该迭代底部部分 20 次,然后退出。我特别不确定分支指令,但我找不到它有什么问题,所以:/
I'm having problems getting my processor to simulate correctly and I think I've narrowed it down to the program I'm giving it.
1. li $R1, 0
2. li $R2, 0x100
3. li $R6, 1
4. li $R8, 0
5. li $R9, 20
6. lw $R3, 0($R1)
7. lw $R4, 4($R1)
8. add $R5, $R3, $R4
9. srlv $R5, $R5, $R6
10. sw $R5, 0($R2)
11. addi $R1, $R1, 4
12. addi $R2, $R2, 4
13. addi $R8, $R8, 1
14. slt $R7, $R8, $R9
15. bne $R7, $zero, -9
It should iterate through the bottom portion 20 times and then exit. I'm particularly unsure about the branch instruction but I can't find anything wrong with it so : /
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您首先将 R8 设为 0,将 R9 设为 20。然后在步骤 13 中,将 R8 加 1,如果 R8 小于 R9,则设置 R7(这将在前 19 次迭代中出现)。如果设置了 R7,则进行分支。循环对我来说似乎很好。
我不记得 bnq 是做什么的... bne 在这里不工作吗?
So, you start with R8 as 0 and R9 as 20. Then in step 13 you add one to R8, then set R7 if R8 is less than R9 (which it will be on the first 19 iterations). Then you branch if R7 is set. Loop seems fine to me.
I don't recall what bnq does... Doesn't bne work here?