title: Assembly MIPS: Nested loops
body: <p>It surely got a bit tricky when I tried to write some code that would print five lines of the asterisk symbol times 4 in each one.</p>
  <pre><code>****
  ****
  ****
  ****
  </code></pre>
  <p>So I thought a nested loop could save the day.
  Boy I was wrong.</p>
  <p>So I made an inner loop for the asterisks and an outer loop for the spaces as below:</p>
  <pre><code>.text
  .globl main
  main:
  add $t0, $zero, $zero   #i counter for the inner loop
  add $t2, $zero, $zero   #j counter for the outer loop
  
  outerloop:
  
      innerloop:
  
          slti    $t1, $t0, 4     #while (i&lt;4)
          beq     $t1, $zero, innerexit
  
          li      $v0, 11         #printf(&quot;*&quot;);
          la      $a0, '*'
          syscall
  
          addiu   $t0, $t0, 1     #i++
  
      j innerloop
      innerexit:
  
  slti    $t3, $t2, 5     #while (j&lt;5)
  beq     $t3, $zero, outerexit
  
  li      $v0, 11         #printf(&quot;\n&quot;);
  la      $a0, '\n'
  syscall
  
  addiu   $t2, $t2, 1     #j++
  
  j outerloop
  outerexit:
  
  li  $v0, 10
  syscall
  </code></pre>
  <p>But the output gives me just one line:</p>
  <pre><code>****
  </code></pre>
  <p>What's the matter with the outer loop?</p>