MIPS input and output array

69 Views Asked by At

Hello , I am trying to get a 5 element array input from the user and then print the elements using MIPS. To do so i wrote the code bellow , but when i run it , I can enter infinte elements so it doesen't stop at 5 elements and then print them. What have I done wrong? Please help!

.data
numbers: .space 20
msg1: .asciiz "Enter 5 numbers:"

.text
.globl main

main:
la $t0 , numbers # saving the adress of array numbers
li $t1 , 0 # counter 

# print msg1
li $v0 , 4
la $a0 ,msg1
syscall

# Get input from user
beq $t1 , 20, print
li $v0 , 5 
syscall
move $t2 , $v0 # save the input in t2
sw $t2 , ($t0) # save t2 in array
addi $t0 , 4   # itereate t0
addi $t1 , 4   # iterate counter

print:
li $t1 , 0 #make caounter 0 again 
beq $t1 , 20 , end
sw $t3 , ($t0) # store the value of array in a register
li $v0 , 1     # print the value 
move $a0 , $t3 
syscall


end:
li $v0 ,10
syscall
0

There are 0 best solutions below