×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Mips x32 simple array problem....

## Mips x32 simple array problem....

(OP)
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...

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!