title: MIPS code for qtspim
body: <p>Hello I'm trying to debug this code. It gives the wrong values for its registers. The code is to test some simple arithmetic and storing of values in different registers. Thank you for your help!</p>
  
  <pre><code>.ent main
  main:
  addi $a0, $0, 10        # r4 = 0 + 10
  addi $a1, $0, 1         # r5 = 0 + 1
  sltiu $s1, $a1, 2       # set if a1 &lt; 2
  add  $t0, $t0, $0       # $t0 = 0
  add $t1, $t1, $a1       # $t1 = $a1 (t1 = 1)
  
  $count:
  add $t0, $t0, $t1       # $t0 = $t0 + $t1   (t0 += 1)
  slti $s1, $t0, 10       # if(a1 &lt; 10) s1 = 1 else s1 = 0
  
  beq $s1, $a1, $count    # while to &lt; 10
  sub $s1, $s1, $a0       # s1 = s1 - a1
  and $s1, $s1, $a0       # s1 = s1 $ a0
  or  $s2, $0, $s1        # s2 = 0 | a0
  
  j $store                # store result
  
  $recount:
  sub $s1, $s1, $a1       # t0 = 0
  
  $store: 
  sw $s1,0($29)           # store s1 on stack
  slti $t3, $s1, 0        # if s1 &lt; 0
  beq $s1, $0, $recount   # goto recount
  lui $t3, 5              # load 5 into $t3
  slt $s3, $t3, $t0       # if t3 &lt; t0
  beq $s1, $0, $end       # goto end
  add $t0, $t0, $0        # t0 = 0
  sw $s1, 0($29)          # store $s3 in $s1
  lw $s4, 4($29)          # pop stack
  
  $end:
  jr $31
  .end main
  </code></pre>