我目前正在尝试将数据变量的地址推入堆栈。在一个单独的过程中,如何更改位于堆栈上的该数据变量的实际值?
我将Visual Studio用作汇编器,并将Irvine32.lib库用于此代码。这是我一直在尝试的方法,但是有错误。
我希望将“计数器”的值从1更改为2,但是它不起作用。我将如何处理?谢谢!
include Irvine 32.inc
.data
counter dword 1
.code
main proc
mov eax, counter
call writeDec ; should print 1
push offset counter ; push address of 'counter' on stack
call foo ; this procedure changes counter from 1 to 2
mov eax, counter ; store counter in eax for writeDec procedure
call writeDec ; should print 2
exit
main endp
foo proc
push eax ; save eax register state
mov eax, esp ; store the stack pointer into eax
add eax, 8 ; navigate through the stack
; this doesn't assemble
mov [eax], 2 ; dereference the stack pointer and set it to 2
pop eax ; restore eax register state
ret
foo endp
end main