title: Mips code : loop error
body: <p>I am working on mips for the 1st time</p>
  
  <p>but my code seems to be stuck in an infinite while loop, I cant understand the problem. when I run my code in Qtspim it gives no errors and displays nothing and the window stops responding:
  little help would be appreciated! Thanks</p>
  
  <pre><code>.data
  arr1:.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  
  .text
  .globl _start
  main:
  
  add $s2,$zero,$zero
  add $s3,$zero,$zero
  add $t3,$zero,$zero
  add $t4,$zero,$zero
  add $s1,$zero,$zero
  
  addi $t5,$zero,31
  addi $t6,$zero,-1
  addi $s0,$zero,12       # s0 = 12
  add $t0,$s0,$zero       #initializing t0 with s0
  addi $t2,$zero,2
  while:
  
      slt $t1,$zero,$t0   #initialization (0&lt;t0)
      beq $t1,$zero,while_exit#if(t1==0){exit}
  
      div $s0,$t2         # s0/2;
      mfhi $s1        # reminder
      mflo $t0        # answer of division    
  
      #add $t5,$t5,$t6        # sub
  
      beq $s1,0,else      #if(s1!=0){else}
      addi $s2,$s2,1      #counting no of ones
      addi $v0,$zero,1
      add $a0,$s1,$zero
      syscall
  j while
  else: 
      addi $s3,$s3,1      #counting no of zeros
      addi $v0,$zero,1
      add $a0,$s1,$zero
      syscall
  j while 
  
  while_exit:
  
  
  addi $v0,$zero,10
  syscall
  </code></pre>