title: How to calculate division remainder in SPARC Assembly?
body: <p>Here is the pseudo code which computes division of two positive integers.<br>
  HR register saves remainder, and LR saves dividend. (and eventually saves root)   </p>
  
  <p>However I think this algorithm has some problem.<br>
  Because this algorithm sometimes don't recover subtraction.(Division is a continuation of subtraction.)  </p>
  
  <p>For example <code>6 / 3 (0110 / 011)</code><br>
  This algorithm subtract -3 one more time. (This situation never occur when we calculate this division by hand)<br>
  So I think this algorithm has some problem.<br>
  Don't you agree with me?
  How to calculate division remainder in Assembly?</p>
  
  <pre><code>for i = 1 to num_of_bits do
  (HR LR) &lt;&lt; 1
  if (HR &gt;= 0) then
     HR = HR - DIVISOR
  else
     HR = HR + DIVISOR
  endif
  if (HR &gt; 0) then LR(lsb) = 1 endif
  endfor
  </code></pre>