i have following mips code and i dont fully understand arrays in mips.The program calculates the arithmetic mean of 4 array values and overwrites the first value of the array.
I know you use the register to point to a address, here in the code line 0:ADDI $2, $0, 0 $2 would point to the beginning of the array. With line 3:LW $3, 1000($2) you will get the value and not the address of the pointer, right?. If it adds all array values together shouldnt line 4:ADD $7, $7, $3 be false? isnt it that this line adds the value in $3 to an adresses in $7 which is the beginning address of the array and not the value? how do you know when you adding addresses and when values? Hope you can clear my confusion.
0:ADDI $2, $0, 0
1:ADDI $7, $0, 0
2:ADDI $4, $0, 16
LOOP:
3:LW $3, 1000($2)
4:ADD $7, $7, $3
5:ADDI $2, $2, 4
6:BNE $2, $4, LOOP
7:SRL $7, $7, 2
8:SW $7, 1000($0)