开发者

Mips x32 using an array

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 load that specific spot in drops and store a number 0-8 to it.....

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: 

 la $t6, drops
 la $t1, 0  #counter


loopStoreRandom:

    move $a0, $s5   # send x 
    jal getDrop
    move $t2, $v0 #t2 has a random number 

    add $t6, $t6, $t2  #random + the whole   ---wrong

    lb $t3, ($t6)       
    bne $t3, -1, loopStoreRandom


    addi $t1, $t1, 1
    beq $t1, 128, exit
    j loopStoreRandom

so as you see i wish there was something that i could to just be like sb $t1, 开发者_开发技巧$t2($t6) but i can't


Your're not restoring $t6 each loop, so the pointer becomes off after the first loop.

Move

la $t6, drops

inside the loop.


jal getDrop
move $t2, $v0 #t2 has a random number 

Assuming v0 is returned from getDrop, the move instruction will be executed BEORE getDrop is executed as it will execute as part of jal's delay slot. So T2 is not going to contain the returned value of getDrop.

should be:

jal getDrop
nop

move $t2, $v0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜