title: How to change the value of a variable with its address stored on the stack?
body: <p>I'm currently trying to push the address of a data variable to the stack. In a separate procedure, how would I change the actual value of this data variable located on the stack?</p>
  
  <p>I'm using Visual Studio as my assembler and using the Irvine32.lib library for this code. This is what I've been trying but there is an error.</p>
  
  <p>I expect the value of 'counter' to be changed from 1 to 2 but it doesn't work. How would I go about this? Thanks!</p>
  
  <pre><code>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
  </code></pre>