title: MIPS, Recursion
body: <p>I trying to write a MIPS program that gets an unsigned integer as argument and returns the sum of all decimal digits in the integer recursively. For example if the argument is 75080 then the sum to be returned is 20 (7+5+0+8+0). Here is my code so far. Any help would be appreciated. </p>
  
  <p>My way of thinking was to divide the number by 10 leaving me with the last integer in the number, add the reminder using mfhi.</p>
  
  <pre><code>.data
  prompt: .asciiz "Enter a string of integer: "
  output: .asciiz "\nThe total sum is: "
      .text
      .globl main
  main:
      la $a0, prompt
      li $v0, 4
      syscall
  
      li $v0, 5
      syscall
  
      move $t2, $v0
  
      la $a0, output
      li $v0, 4
      syscall
  
  Loop:
      div $t2, $t2, 10
      mflo, $t1
      mfhi, $t3
      beqz $t1, Exit
      add $t1, $t1, 0
      b additive
  
  additive:
      add $t0, $t1, $t1
      j Loop
  
  Exit:   
          la $a0, output
              li $v0, 4
              syscall
              la $v0, 10
              syscall
  </code></pre>