title: Recursive call with "counter" in MIPS assembly language
body: <p>I am trying to troubleshoot/understand possible problems in my MIPS assembly programming assignment. It is fairly basic, we must implement a recursive call that updates a "counter" and exits the loop when the counter reaches 0. My error, according to PCSpim, shows the counter value as NULL when I run the program. </p>
  
  <pre><code>.data
  string: .asciiz "Recursive call counter "
  
  .text
  .globl main
  
  
  main:       
      subu    $sp, $sp, 32        # create stack frame
  
      sw  $ra, 28($sp)        # save ($fp, $ra) registers
      sw  $fp, 24($sp)
  
      addu    $fp, $sp, 28        # set up the new frame pointer
  
      sw  $s0, 20($sp)        # save other GPR’s
  
      li  $s1, 10         # load counter to $s1
  
      li  $v0, 4          # print counter message and counter
      la  $a0, string
      syscall
      li  $v0, 4
      la  $a0, ($s1)
      syscall
  
      jal recursive_call      # jump to recursive call
  
  
  
      lw  $s0, 20($sp)        # restore registers
  
      lw  $fp, 24($sp)        # restore SP, FP, $ra for the caller
      lw  $ra, 28($sp)        
  
  
      addu    $sp, $sp, 32        # restore the caller's stack pointer
  
      jr $31              #end program
  
  
  
  
  recursive_call:
      subu    $sp, $sp, 32        # create stack frame
  
      sw  $ra, 28($sp)        # save ($fp, $ra) registers
      sw  $fp, 24($sp)
  
      addu    $fp, $sp, 28        # set up the new frame pointer
  
      sw  $s0, 20($sp)        # save other GPR’s
  
      sub     $s1, $s1, 1     # subtract one from counter
  
  
      li  $v0, 4          #print counter number
      la  $a0, ($s1)
      syscall
  
      beq     $s0, $zero, SKIP    # if counter = 0, go to skip
  
      jal     recursive_call      # jump to recursive call
  
  
  SKIP:   
      lw  $s0, 20($sp)        # restore registers
  
      lw  $fp, 24($sp)        # restore SP, FP, $ra for the caller
      lw  $ra, 28($sp)        
  
  
      addu    $sp, $sp, 32        # restore the caller's stack pointer
  
      jr $ra
  </code></pre>
  
  <p>Any help would be greatly appreciated. I will continue to troubleshoot and see if I come up with anything.</p>