title: How to save string into an array in mips
body: <p>I have a problem with this code. I try to enter a string by input and save it into an array, this my code:</p>
  
  <pre><code>    .data
      .align 2
  array:  .space 80
  size: .word 20
  string: .space 20
  op: .asciiz "Enter the array length"
  prompt: .asciiz "Enter a string:"
  text:   .asciiz "The array of string is:"
  newline: .asciiz "\n"
      .text
      .globl main
  
  main:
      add $t0, $zero, $zero # index of array
      addi $t1, $zero, 1 # counter=1
  
      li $v0, 4
      la $a0, op
      syscall
      jal new_line
  
      li $v0, 5
      syscall
  
      addi $s0, $v0, 0 # $v0 contains integer read
  read_string: 
      bgt $t1, $s0, L1 # if ($t1 &gt; length)then go to L1
  
      li $v0, 4
      la $a0, prompt
      syscall
  
      la $a0, string
      li $a1, 20
      li $v0, 8
      syscall
  
      sw $a0, array($t0)
      addi $t0, $t0, 4
      addi $t1, $t1, 1
  
      j read_string
  
  L1: #### here i want to print the array ####
      add $t0, $zero, $zero # index of array
      addi $t1, $zero, 1 # counter=1
  
      la $a0, text
      li $v0, 4
      syscall
      jal new_line
  
      while: bgt $t1, $s0, done
      lw $t2, array($t0)
  
      li $v0, 4
      move $a0, $t2
      syscall
      jal new_line
  
      addi $t0, $t0, 4
      addi $t1, $t1, 1
      j while
  
      new_line: la $a0, newline
      li $v0, 4
      syscall
      jr $ra
  
  done: li $v0, 10
      syscall
  </code></pre>
  
  <p>The trouble is that this program show me the last string that I've entered by input, for example</p>
  
  <pre><code>Enter the array length:
  2
  Enter a string:asd
  Enter a string:123
  The array of string is:
  123
  
  123
  </code></pre>
  
  <p>Please I need some help, thanks a lot and have a nice day.</p>