user1766888
user1766888

Reputation: 409

Get user input for integers and store in array

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:

Upvotes: 0

Views: 1054

Answers (1)

ooga
ooga

Reputation: 15511

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

Upvotes: 1

Related Questions