title: Nested loop in mips assembly
body: <p>I have to write the following C loop in mips assembly:</p>
  
  <pre><code>for (i=0;i&lt;5;++i)
  {
     for (k=0;k&lt;4;++k)
     {
        printf ("*");
     }
   printf ("\n");
  }
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>.data
  i: .word 0 
  k: .word 0 
  limit: .word 4 
  line: .word 5 
  char: .byte '*'
  newline: .byte '\n'
  
  .text
  .globl main
  main:
  lw $t0,i
  lw $t1,k
  lw $t2,limit
  lw $t3,line
  print:
  beq $t0,$t3,exit    
  lb $a0,char
  li $v0,11
  addi $t1,$t1,1
  syscall
  bne $t1,$t2,print
  addi $t0,$t0,1
  lb $a0,newline
  li $v0,11
  syscall
  bne $t0,$t3,print
  exit:
  li $v0,10
  syscall
  </code></pre>
  
  <p>This prints the first line as intended but after newline character the program enters an infinite loop and prints stars constantly.I am really confused on how to deal with nested loops in assembly.I tried to convert the C loops in if conditions and it helped a bit but still something is wrong.
  Any help is appreciated.</p>