I want to replicate this the most cleanest way possible
In python
A = [0,0,0,0,0]
i = 0
while(i != 5):
A[i] = 10
i++
That is, I want to iterate through an array and sets all its values to [10,10,10,10,10]
This is what i've done in mips assembly
.data
array: .word 0:5
.text
main:
li $t1, 0 # i = 0
la $t9, array # $t9 = addr(array)
li $t8, 10 # $t8 = 10
start_loop:
beq $t1, 5, end_loop # if i == 5 jump to end loop
sll $t2, $t1, 2 # $t2 = i x 4
add $t2, $t9, $t2 # $t3 = addr(array[i])
sw $t8, 0($t2) # array[i] = $t8
addi $t1, $t1, 1 # i = i + 1
j start_loop
end_loop:
li $v0, 10 # end program
syscall
I feel like I used so many registers and this isn't the most clean way to do this. Any help appreciated
(Also making sure to use a loop I could hard code this without a loop but im just trying to find out other ways to use loops)