Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mips x32 simple array problem....

Status
Not open for further replies.

basketball8533

Programmer
Mar 23, 2011
1
US
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...


storeArray:

li $t1, 0 #counter
li $t2, 0
loopStoreRandom:
la $t6, drops
bgt $t2, 128, exit
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



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


exit:
lb $t5, 2($t6)
move $a0, $t5
li $v0, 1
syscall
li $v0, 10
syscall


It prints -1 everytime... and thats not what i want...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top