I'm a novice to MIPS
I'm trying to develop a program which takes an input from a ten word array, increments it by two, stores the result back into a register $v0. Which will hold the incremented value. The program should stop when it encounters a value of 0 from the array.
The first 9 elements of the array will start from 1 up to 9, with the tenth being a 0.
Another register will also be used to hold the sum of all incremented values.
I can also not make use of any pseudo code.
This is the code i have so far
lui $a0, 0x1001 #load address 0x1001000 of the array into register $a0
jal incrment #call the procedure
lw $a2, 0($a0) #load word from register $a0 into $a2
beq $a2, $zero, else #if word loaded is 0 goto else
addi $a2, $a2, 2 #add two
sw $a2, 0($a0) #store result from $a2 back into $a0
addi $a0, $a0, 1 #add 1 to $a0 to point to the next value in the array
addi $v0, $a2, $zero #add the result from $a2 into $v0
addi $v0, $zero, 1
j increment #jump back to the procedure
add $v1, $a0, $zero #once the 0 is found, store the final sum from $a0 into $v1
addi $v1, $zero, 1
I feel like the logic is correct but the semantics of the code are lacking
The code may seem like a bit of a mess, another area I'm also unsure about is the index, i'm supposed to use another register to hold the 0 based index of the array?
If you can't fix it, then could you give me some pointers? Thanks