MIPS数组迭代表示​​法?

时间:2013-10-23 03:56:37

标签: arrays mips

我有一个关于MIPS关于数组的一些符号的快速问题,我很困惑。

假设我在$ t0中有一个值。它可能是任何东西,我们会说3。

我想要做的是将存储在该索引中的值($ t0中保存的值)增加1。

是正确的表示法:addi array($t0), array($t0), 1

或者是:addi $t0($s7), $t0($s7), 1 #assuming the array has been loaded into register $s7

例如,如果$ t0中有3个,那么我想将数组[3]的值增加1。

1 个答案:

答案 0 :(得分:1)

MIPS是load/store architecture,因此您必须将值加载到寄存器中,递增它,然后将其存储回来:

sll $t1, $t0, 2     # $t1 = index * sizeof(word)
add $t1, $s7, $t1   # $t1 = &array[index]
lw $t2, ($t1)       # $t2 = array[index]
addi $t2, $t2, 1    # $t2++
sw $t2, ($t1)       # array[index] = $t2