0

I'm trying to ask the user for an input for the number of integers they want to enter and then loop through that amount. Also I want to feed each value after that into an array but I'm running into an issue checking that the loop continues until the sentinel value the user enters. li doesn't accept two registers as arguments, is there some other way to do this?

.data

    arr1:
         .word 0:50 #allocate space for 50 integers (4-bits)
    msg:
         .asciiz "Give me the quantity of numbers:\n"

.text

 main:
         #print message
         li $v0, 4
         la $a0, msg    
         syscall

         #read int
         li $v0, 5
         syscall

         #store initial loop value
         move $t0, $v0

         li $8, 0
         li $13, $t0 #sentinel value for loop
         for:
              bge $8, $13, end_for #end the loop when you reach then number entered earlier

              #keep reading numbers
              li $v0, 5
              syscall

              move $t1, $v0
              la $9, arr1 #base address for array
              mul $10, $8, 4 #offset of 4 bytes
              add $11, $10, $9 #address for new element
              li $12, $t1
              sw $12, ($11) #save element at address
              add $8, $8, 1 #increment loop
              b for
          end_for:

1 Answer 1

1

li stands for "load immediate", so it always takes one register and one immediate value. To copy one register value to another register, use move destination source

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.