MIPS 中的数组索引有点麻烦。假设我有以下 C 代码:
void main() {
.
.
int[2] a; # or any other length
.
.
a[1] = 7; # or any other number
.
.
}
假设我知道帧指针的“a”偏移量例如为 12,因此:
lw t0, -12($fp)
给我'a'的基址。现在假设数组访问索引值(在本例中为 1)存储在 $t1 中。但我不知道它是什么。如何将 7 存储在 [1] 中?我正在寻找类似的东西:
mul $t1, $t1, -4 # since each integer takes 4 bytes
addi $t1, $t1, -12 # t1 = exact offset from $fp to a[1]
li $t2, 7 # t2 = 7
sw $t2, $t1($fp)
问题是最后一个操作是非法的(尽管Integer array indexing with MIPS assembly)。我怎样才能做到这一点?谢谢