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
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]
Any help would be really appreciated.
Thank you in advance!!
The line:
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.
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.
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.