I would like to pass an 'inputCounter' parameter by pushing it onto the stack. Within the procedure, I dereferenced the stack pointer pointing to this parameter, and would like to add it to the address of array and then increment it by 4 (size of the array) However, I am getting an error of:
Exception thrown at 0x00403729 in Project.exe: 0xC0000005: Access violation writing location 0x0080C0ED.
I am using Visual Studio and the irvine32.inc library.
I've tried debugging ebx (the register I hold my inputCounter in) and in the first run through I expect it to be 0 and then the second run, I expect it to be 4. However, it starts at 0 (which was defined in my main) but then it jumps to '0040607B' for some reason. And the error occurs with the line:
mov [esi], eax.
Help would be much appreciated!
include Irvine32.inc
.data
array dword 2 DUP (?)
inputCounter dword 0
.code
main proc
mov esi, offset array
mov ecx, lengthof array + 1
mov ebx, 0
loopMain:
push offset inputCounter ;push the address of inputCounter onto the stack
call input
push offset inputCounter ;push the address of inputCounter onto the stack
call input
loop loopMain
exit
main endp
input proc
pushad ;save all registers
mov ebx, [esp + 36] ;store inputCounter into ebx
mov edx, offset prompt ;address of the prompt
call writeString
call readInt
add esi, ebx ;add 'inputCounter' to address of array
mov [esi], eax ;*error occurs here*
add dword ptr[ebx], 4 ;increment 'inputCounter' by 4 (size of array)
popad ;restore all registers
ret
input endp
end main
User contributions licensed under CC BY-SA 3.0