So... I have been trying to make a generic for loop to use for MIPS, but I can′t get it to work... I was thinking about using what I understood it was stacks... but it seems to still be very wrong... Basically trying to do this:
for(i=0; i<10; i++){
for(j = i; j<10; j++){
acc = acc + a[j];
}
}
With this generic for function that does not work:
for:
addi $sp, $sp, -4
sw $a1, ($sp)
addi $sp, $sp, -4
sw $a2, ($sp)
addi $t0, $a2, 0
la $s7, ($ra)
jr $s7
counter:
addi $t0, $t0, 1
jr $s7
increment:
blt $t0, $a1, counter
addi $sp, $sp, 4
addi $sp, $sp, 4
jr $ra
Kinda like this:
# for(i=0; i<10; i++)
addi $a1, $zero, 9
la $a2, ($s0)
addi $t3, $zero, 0
sw $t3, ($s0)
jal for
sw $a2, ($s0)
# for(j = i; j<10; j++)
addi $a1, $zero, 9
la $a2, ($s1)
lw $t2, ($s0)
addi $a2, $t2, 0
jal for
# acc = acc + a[j]
la $s3, vector
add $t4, $zero, $t1
jal set_address
lw $t4, ($s3)
add $t3, $t3, $t4
# j++
jal increment
lw $a2, ($sp)
addi $sp, $sp, 4
lw $a1, ($sp)
# i++
jal increment
I had a bunch of other comments on this code but they were not in english so I thought it would be less confunsing... Also... I am quite aware I did not follow formalities, however I was not aware of them until now and if I cant get this to work I will have to use a different way to solve this issue.