Hey Everybody... im writing this code for one of my assignments and i need to have an array of size 128 which i do by
drops: .space 128
so that i can take a random number,
use that as the index and store a number 0-8 to it.....
so that in the end when i hit that number it will print out a number 0-8
for example.... say the random number was 32 and i was on the first iteration of the loop it would store 0 in the 32nd spot of the array if i was in the 2 iteration of the array... it would store 1 in the random number eg 92..spot
here is my code:
I first made everything in my array -1 so that i can test to see if something was in it...
Code:
storeArray:
la $t6, drops
li $t1, 0 #counter
li $t2, 0
loopStoreRandom:
bgt $t2, 128, exit
la $t6, drops
move $a0, $s5 # send x
jal getDrop
move $t2, $v0
add $t6, $t6, $t2 #random + the whole
lb $t3, ($t6)
bne $t3, -1, loopStoreRandom
sb $t1, ($t6)
addi $t1, $t1, 1
addi $t2, $t2, 1
beq $t1, 8, sub8
j loopStoreRandom
sub8:
addi $t1, $t1, -8
j loopStoreRandom
so as you see i wish there was something that i could to just be like sb $t1, $t2($t6) but i cant...
whenever i test the code in exit... ex
Code:
exit:
lb $t5, 32($t6)
move $a0, $t5
li $v0, 1
syscall
li $v0, 10
syscall
it prints different numbers everytime i change the index in my test code... ex lb $t5, 2($t6) prints out a -120