Reputation: 1
A[k++] = A[k] + A[k]
# i-> $s0, k-> $s1 , base of A[] ->$s2
i tried the following but can't figure out how to store back in array A[k++]....
sll $t0 , $s1 , 2
add $t0 , $t0 , $s2
lw $t1, 0($t0)
add $s1, $t1 , $t1 # i added A[k] + A[k]
Upvotes: 0
Views: 442
Reputation: 41
In order to iterate throught arrays in MIPS, you need to add 4 bytes for each position of the array. Example:
.data
myArray: .store 12 # array with length of 3 (3 x 4 bytes)
.text
li $t0, 0
li $s0, 1
sw $s0, myArray($t0) # myArray[0] = 1
addi $t0, 4
sw $s0, myArray($t0) # myArray[1] = 1
addi $t0, 4
sw $s0, myArray($t0) # myArray[2] = 1
Upvotes: 1