好的,所以我在内存中存储了一个数组,我想本质上创建一个变量“i”并获取索引 i 处的数组值。我如何在 MIPS 中执行此操作?提前致谢!这是我的代码。
.data
array: .word 0:100
.text
li $t0, 5 #this is my representation of "i"
la $t2, array
lw $t1, i($t2) #this is where i am messed up.
最佳答案
您应该将基数和索引相加,并记住将字长按 4 倍缩放。像这样的事情:
li $t0, 5 # this is my representation of "i"
la $t2, array
sll $t1, $t0, 2 # scale by 4
addu $t1, $t1, $t2 # add offset and base together
lw $t1, ($t1) # fetch the data
如果 i
是适合 16 位的立即常量,则只能使用 i($t2)
样式。
关于assembly - MIPS - 获取数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28491018/