title: How to use the div instruction to find remainder in x86 assembly?
body: <pre><code>mov eax, 0
  mov ebx, 0
  mov edx, 0
  mov ax, 31
  mul cx
  mov bx, 12
  div bx
  add bp, ax
  mov eax, 0
  mov ebx, 0
  mov bp, bp
  mov al, 7
  div al
  </code></pre>
  
  <p>can anyone tell me whats wrong with the div al instruction in this block of code, so as I'm debugging every number of bp i calculated, when i divide by al it give me 1 as the remainder, why is this happen? </p>
  
  <p>the remainder should be store back to ah register </p>
  
  <p>thank in advance </p>
  
  <p>edited code :</p>
  
  <pre><code>mov eax, 0
  mov ebx, 0
  mov edx, 0
  mov ax, 31
  mul cx
  mov bx, 12
  div bx
  add bp, ax
  mov eax, 0
  mov ebx, 0
  mov ax, bp
  mov bl, 7
  div bl
  mov al, 0
  </code></pre>