MIPS addi指令对数组基数 [英] MIPS addi instruction to array base
问题描述
我是MIPS的新手,并且很难弄清楚这段代码的含义……其中$ s6是数组A的开始:
I'm a newcomer to MIPS and am having a hard time figuring our what this snip of code means... Where $s6 is the start of an array A:
addi $t0,$s6,4
我不确定这是否意味着$ t0 = A [4]-或者-如果它表示$ t0 = A [0] + 4,则取A [0]中的值,然后加上四个,然后将其保存回A [0]
I'm not sure if this means $t0 = A[4] -or- If it means $t0 = A[0] + 4, take the value in A[0] and add four to it saving it back into A[0]
任何帮助将不胜感激.
先谢谢您!
推荐答案
该行:
addi $t0,$s6,4
其中$ s6是数组的基数,它取寄存器$ s6的内容,将其加4,然后将结果放入$ t0.因此,如果$ s6中的地址为0x00400000,则在addi指令之后,$ t0将包含0x00400004.
where $s6 is the base of the array, is taking the contents of register $s6, adding 4 to them and putting the result into $t0. Thus, if the address in $s6 is 0x00400000, after the addi instruction, $t0 would contain 0x00400004.
addi指令将立即数即整数值添加到源寄存器并将结果存储在目标寄存器中,在本例中为$ t0.
The addi instruction adds an immediate value, i.e. an integer value, to the source register and stores the result in the destination register, in this case $t0.
因此,如果$ s6为A [0],则假定您有整数数组,则$ t0变为A [1].如果您有一个字符数组,即一个字符串,则$ t0变为A [3].$ t0不保存这些数组索引的值,而是保存这些数组索引的地址,因为这就是$ s6最初保存的内容.
So if $s6 is A[0], then $t0 becomes A[1], assuming you have an integer array. If you have a character array, i.e. a string, then $t0 becomes A[3]. $t0 does not hold the value at these array indices, it holds the address of these array indices, because that is what $s6 originally held.
这篇关于MIPS addi指令对数组基数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!