Reputation: 211
I'm working on a homework assignment right now, and I'm given this information:
$s6 is the location of the base address of array A, $s0 is the location of the value of f (not specified).
It wants me to convert some instructions to a C statement. Here is my question though, because if this is answered I can very easily do the rest of this problem:
add $t0, $s6, $s0
Is that saying $t0 = (the base address of array A) + f
or is it saying $t0 = A[0+f]
?
Because if the base address of A were 0x04000000 and I used addi to add 4 to that base address, yielding 0x04000004, and assigning that value to t0, what I'm saying is that t0 = A[1] (assuming I'm storing integers).
But since I don't know the value of f, I'm unsure of how to represent this in C, because I know I'm modifying the index, but I don't know by how much. Would it be more accurate to say (given the instruction above):
$t0 = A[f/4]
I'm new to all of this ha. Hopefully I demonstrated that I've done a bit of research trying to figure this out.
Thanks
OSFTW
Upvotes: 1
Views: 322
Reputation: 225232
There is no dereferencing in this instruction:
add $t0, $s6, $s0
It's like saying
t0 = s6 + s0;
In a C-like pseudocode. Or for your example:
t0 = (char *)A + f;
To get a value out of A, it would look something like:
lw $t1, 0($t0)
After having done the previous add
instruction so that $t0
points to the right place in the array.
Upvotes: 1