1

So I'm trying to put 10 numbers that are between 0-50 into an array.

    li  $t0, 0      #loopcounter = 0
    la  $a0, array
    addi    $a0, $0, 0  #initialize array index = 0
    loop:
            li  $v0, 5
            syscall
            blt $v0, 0, loop
            bgt $v0, 50, loop
            add $t0, $t0, 1   #increment loop counter

            sw  $a0, 0($a0)     # ERROR HERE #store value of $v0 at index 0
            addi    $a0, $a0, 4     # Increment the index by 4


            blt $t0, 10, loop

How would I go about putting those 10 numbers into my array at $a0 and then be able to access them later?

1
  • See the MIPS instruction set. Specifically the SW instruction. Commented Apr 8, 2013 at 12:17

1 Answer 1

1

This will

addi $a0, $0, $0     # initialize index with 0
sw $v0, 0($a0)       # store value of $v0 at index 0
addi $a0, $a0, 4     # Increment the index by 4
sw $v0, 0($a0)       # store value of $v0 at index 1

and so on...

I left the loop part for you.

Why increment by 4 ?

Becuase integers in MIPS takes up 32 bits or 4 bytes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.