title: how to use mod in assembly x86
body: <p>I have a question on assembly x86 architecture.</p>
  
  <pre><code>INCLUDE Irvine32.inc
  .data
  day BYTE 0
  month BYTE 0
  year BYTE 0
  
  a BYTE 0
  y BYTE 0
  m BYTE 0
  count BYTE 0
  
  prompt1 BYTE "enter month: ",0
  prompt2 BYTE "enter day: ",0
  prompt3 BYTE "enter an year: ",0
  prompt4 BYTE " the day of the week is ",0
  .code
  main PROC
  
  mov edx, OFFSET prompt1
  call writeString
  mov eax, OFFSET month
  mov ecx, 19
  call readInt
  call crlf
  
  mov edx, OFFSET prompt2
  call writeString
  mov eax, OFFSET day
  mov ecx, 19
  call readInt
  call crlf
  
  mov edx, OFFSET prompt3
  call writeString
  mov eax, OFFSET year
  mov ecx, 19
  call readInt
  call crlf
  
  mov al, 14
  sub al, month
  mov bl, 12
  div bl
  mov a, al
  mov al, 0
  
  mov ah, year
  sub ah, a
  mov y, ah
  mov ah, 0
  
  mov bh, 12
  mul a
  add bh, a
  mov ch, 2
  sub bh, ch
  mov m, bh
  mov bh, 0
  mov ch, 0
  
  mov al, 31
  mul m
  mov ah, 12
  div ah
  
  mov bl, y
  mov bh, day
  add bh, y
  
  mov cl, y
  mov ch, 4
  div ch
  add bh, cl
  
  mov dl, y
  mov dh, 4
  div dh
  add bh, cl
  add bh, al
  mov al, 0
  
  mov al, 7 // mod 7
  div al
  
  
  
      exit
  main ENDP
  
  END main
  </code></pre>
  
  <p>So I am supposed to do these arithmetic equations:</p>
  
  <pre><code>a = (14 - month) / 12
  y = year - a
  m = month + (12 * a) - 2
  d = (day + y + y/4 - y/100 + y/400 + (31 * m / 12)) % 7
  </code></pre>
  
  <p>For the last equation of <code>mod 7</code>, I got an error, "integer overflow", this is due to using <code>bl</code> I think.</p>
  
  <p>If I do something like this</p>
  
  <pre><code>mov ax, "thing in parenthesis" 
  mov cl, 7
  div cl      
  </code></pre>
  
  <p>then I would get <code>al</code> is quotient, <code>ah</code> is remainder.</p>
  
  <p>But how would I do <code>mod</code> without having to use <code>ax</code> register?</p>