title: while loop with an array in mips
body: <p>Consider the following c or java-like code:
  <code>int i = 0; int x = 5; int A[10];</code> 
   declare an array of integers with 10 element <code>while (i &lt; 10) { A[i] = i+x; i++; }</code>
  Write a MIPS program to implement the program. Use as few instructions as possible.</p>
  
  <p>I can't seem to figure this out.
  Heres what i have done.</p>
  
  <pre><code># i=0, x=5. Array is 10 elements. (While i&lt;10, A[i]=i+x, i++.)
  # Array should be [5,6,7,8,9,10,11,12,13,14]
      .data
  intgrs: .word 0:10  # array of 10 elements to contain integers
  size:   .word 10    #size of array
      .text
      .globl main
  main:
      la $t0, intgrs  # load address or array
      la $t5, size    # load address of size variable
      lw $t5, 0($t5)  #load array size
      li $t2, 0   # i=0
      li $t6, 5   # x=5
  loop:
      add $t4, $t2, $t6 # i+x
      sw $t4, 0($t0)  # A[0] = 0+5 = 5
      add $t2, $t2, 1 # i++
      beq $t2, $t5, loop
  exit:   li $v0, 10  # exit system call
      syscall
  </code></pre>