Im trying to convert the following C code to MIPS but im having trouble understanding how you take the [k-1] in the array.
int vek[100];
main()
{
int k;
int first = vek[0];
for (k = 1; k < 100; k++)
{
vek[k - 1] = vek[k];
}
vek[k – 1] = first;
}
Here is what i got so far:
.data
vek: .space 400
.text
main:
addi s0,zero,1 #k = 1
addi s1,zero.100 #value 100
la t1,vek #t1 as index in vek
add s2,t1,zero #first = vek[0]
L1:
bgt s0,s1,end #if k is bigger then 100 jump to end label
addi s0,zero,-1 #k-1
sll t2,s0,2 #t2 = 4*k next space in the array
here is where i lose myself, i don't understand how i am supposed to get the rest of the code translated. Since there is a lack of MIPS tutorials on the web you are my last chance. If some kind soul could help translate the last part of the code and give me an explanation that would be great.
P.S this is not something i'm going to use its simply just an example of an question that will be on the exam.