title: MIPS Calculator implementing division with subtraction and addition, avoiding DIV and REM instructions
body: <p>I'm working on the classic MIPS calculator example, but am attempting to change the divis (division) routine below to use only addition and subtraction instead of MIPS div operation (similar to what I have done with multiplication). This is probably very easy to do, but I am new to MIPS and every attempt I have made so far hasn't worked. Help?</p>
  
  <p>I'm using qtspim as my simulator</p>
  
  <p>What I have so far for division:</p>
  
  <pre><code>    start_divis:    
          add $t1, $zero, $s0   #make copy of first integer value in $s0
          add $t2, $zero, $s1   #make copy of second integer value in $s1
          add $t0, $zero, $zero #make $t0 the temporary variable to act as a counter
  
      div_loop:
          slt $t3, $t2, $t1        #checks if $t1 &gt; $t2
          sub $t1, $t1, $t2        #subtract $t2 from $t1
          addi $t0, 1              #add one to counter
          bne $t3, $zero, div_loop #if first number &lt; second number, loop
  
      end_divis:
          move $s5, $t0      #store answer  
          move $s6, $t1      #store remainder
          la  $a0, divi_s    #get division symbol
          move $s7, $a0      #move it to $s7
  
          j div_ans          #jump to div_ans
  </code></pre>