Unhandled exception at 0x0000007b in Project.exe: 0xC0000005: Access violation

0

I am trying to figure out why I am getting this error:

Unhandled exception at 0x0000007b in Project.exe: 0xC0000005: Access violation

Firstly I am unsure what happens in this instruction: MOV EAX, 100 Because I already store 123 into EAX. When I debugged the program, it states that EAX = 100 after running the argument through the procedure ran. MY question is, does the MOV EAX,100 replace the 123?

Also at the end of the procedure, I attaint the error. Is it because of the mov statement inside he procedure. please explain...

.code
main PROC
mov EAX, 123 ;Argument
MOV EBX, 456 ;Argument

call ran

     exit
main ENDP

ran PROC
     push eax ;save eax
     push ebx ;save ebx
     mov eax, 100 ;store 100 to eax?

     pop ebx
     ret
     exit
ran ENDP

END main
assembly
compiler-construction
masm
masm32
asked on Stack Overflow May 6, 2014 by monkey doodle

1 Answer

2

Two push, but only one pop. Should be farily obvious why the exception occurs.

 push eax ;save eax
 push ebx ;save ebx
 mov eax, 100 ;store 100 to eax?

 pop ebx
 ret

If you push somthing on the stack, you must ensure that the stack balances by either manually adjusting it, or by using the same number of pop as you pushed before. In your case the ret instruction will jump somwhere where eax originally pointed to.

0x7b == 123  == eax
answered on Stack Overflow May 6, 2014 by Devolus

User contributions licensed under CC BY-SA 3.0