加载MIPS寄存器中存储的地址
我有一个小问题,我似乎无法解决。我有几个数字以以下方式存储在堆栈中:
|5| 0($sp)
|4| 4($sp)
|3|
|8|
我想遍历堆栈,一次比较两个数字。我的意思是,我想比较 0($sp) 与 4($sp),然后比较 0($sp) 与 8($sp),...,然后比较 4($sp) 与 8($ sp)。所以,5 vs 4、5 vs 3、5 vs 8、4 vs 3、4 vs 8、3 vs 8。
我的尝试主要是
lw $t3, 0($sp) ##
la $t4, 4($sp) ##
Sum2:
beq $t2, $zero, Exit
lw $t5, $t4 ##
add $a0, $t5, $zero
li $v0, 1
syscall
add $t4, $t4, 4
addi $t2, $t2, -1
j Sum2
第一、第二和第五行。 我将堆栈顶部的整数值加载到 $t3 中,并将堆栈中下一个项目的地址加载到 $t4 中。
然后我想加载 $t4 中存储的地址处的值,进行比较(现在我只是加零,这样我就可以打印它),然后将 t4 中存储的地址增加4 个字节用于获取堆栈中的第 3 项。我会继续这样做,直到寄存器值达到 0 。一旦发生这种情况,我会将 $sp 加 4 并重复该过程。
每当我尝试在 PCSpim 中加载它时,都会收到语法错误。我做错了什么?
I'm having a small issue that I can't seem to get around. I have several numbers stored in the stack in the following fashion:
|5| 0($sp)
|4| 4($sp)
|3|
|8|
I want to traverse the stack, comparing two numbers at a time. By this, I mean that I want to compare 0($sp) with 4($sp) and then 0($sp) with 8($sp), ..., and then 4($sp) with 8($sp). So, 5 vs 4, 5 vs 3, 5 vs 8, 4 vs 3, 4 vs 8, 3 vs 8.
My attempt at this is to
lw $t3, 0($sp) ##
la $t4, 4($sp) ##
Sum2:
beq $t2, $zero, Exit
lw $t5, $t4 ##
add $a0, $t5, $zero
li $v0, 1
syscall
add $t4, $t4, 4
addi $t2, $t2, -1
j Sum2
Mainly the 1st, 2nd, and 5th lines.
I'm loading the value the integer on the top of the stack into $t3 and loading the address of the next item in the stack into $t4.
Then I want to load the value at the address stored in $t4, do my comparison (right now i'm just adding to zero so I can print it) and then increment the address stored in t4 by 4 bytes to get the 3rd item in the stack. I would keep doing this until a register value hits 0 . Once this occurs, I'll increment the $sp by 4 and repeat the process.
Whenever I try to load this in PCSpim, I get a syntax error. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确地阅读了您的问题,您希望
使用存储在 $t4 指向的位置的值加载 t5 。
If I'm reading your problem correctly, you want
to load t5 with the value stored where $t4 points.