title: Access violation writing location in assembly x86
body: <p>Hi i have a question about assembly x86 </p>
  
  <p>this is my code </p>
  
  <pre><code>INCLUDE Irvine32.inc
  .data
  day WORD 0
  month WORD 0
  year WORD 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 edx, 0
  call readInt
  call crlf
  mov month, ax
  
  mov eax, 0
  mov edx, OFFSET prompt2
  call writeString
  mov edx, 0
  call readInt
  call crlf
  mov day, ax
  
  
  mov eax, 0
  mov edx, OFFSET prompt3
  call writeString
  mov edx, 0
  call readInt
  call crlf
  mov year, ax
  
  
  
  mov eax, 0
  mov ebx, 0
  mov ax, 14
  sub ax, month
  mov bx, 12
  div bx
  mov si, ax ;; a store in si
  sub year, ax
  mov di, year ;; y store in di
  mov ax, ax
  mul bx
  add ax, month
  mov cx, 2
  sub ax, cx
  mov ecx, 0
  mov cx, ax ;; m store in cx
  
  mov eax, 0
  mov ebx, 0
  mov esp, 0
  mov ebp, 0
  
  add day, di
  mov ax, di
  mov bx, 4
  div bx
  add day, ax
  mov sp, day
  mov eax, 0
  mov ebx, 0
  mov ax, di
  mov bl, 100
  div bl
  mov ah, 0
  sub day, ax
  
  
  mov eax, 0
  mov ebx, 0
  mov dx, 0
  mov ax, di
  mov bx, 400
  div bx
  add day, ax
  mov bp, day  ;; temporary holder for d value up to y/400 calculation
  
  mov eax, 0
  mov ebx, 0
  mov ax, 31
  mul cx
  mov bx, 12
  div bx
  add bp, ax
  mov al, 7
  div al
  
  
  
  
      exit
  main ENDP
  
  END main
  </code></pre>
  
  <p>I' m debugging this code everything seems to work accordingly, until I reach the exit instruction then visual studio gave me this error " Access violation writing location 0x000009DF",  I a bit confused that it gave me this error at the end of the code, why would there be access violation at the exit command</p>
  
  <p>this is my input </p>
  
  <pre><code>enter month: 4
  
  enter day: 15
  
  enter an year: 2013
  </code></pre>
  
  <p>At the end of the program i get value of register al = 1 which is what i want 
  so I don't know why it gave me this error when there is no other error in the code 
  can anyone help ?
  thank in advance</p>