Access violation writing location in assembly x86 -


hi have question assembly x86

this 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 year: ",0 prompt4 byte " day of week ",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 ;; 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 d value 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 

i' m debugging code seems work accordingly, until reach exit instruction visual studio gave me error " access violation writing location 0x000009df", bit confused gave me error @ end of code, why there access violation @ exit command

this input

enter month: 4  enter day: 15  enter year: 2013 

at end of program value of register al = 1 want don't know why gave me error when there no other error in code can ? thank in advance

i found error line mov sp, day, did not set esp 0 before thats why program show access violation


Comments