Я хотел бы передать параметр inputCounter, поместив его в стек. В рамках процедуры я разыменовал указатель стека, указывающий на этот параметр, и хотел бы добавить его к адресу массива, а затем увеличить его на 4 (размер массива). Однако я получаю сообщение об ошибке:
Исключение, выданное в 0x00403729 в Project.exe: 0xC0000005: Место записи нарушения прав доступа 0x0080C0ED.
Я использую Visual Studio и библиотеку irvine32.inc.
Я попытался отладить ebx (регистр, в котором хранится мой inputCounter), и в первом прогоне я ожидаю, что он будет равен 0, а затем во втором прогоне, я ожидаю, что он будет равен 4. Однако он начинается с 0 ( который был определен в моем основном), но затем он переходит к «0040607B» по какой-то причине. И ошибка происходит со строкой:
mov [esi], eax.
Помощь будет высоко ценится!
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