Alo
After I read about the function and stack from http://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames I have a question about local variables.
Snapshot from the article:
push ebp ; save the value of ebp mov ebp, esp ; ebp now points to the top of the stack sub esp, 12 ; space allocated on the stack for the local variables
This means that access to local variables can be obtained by referring to ebp. Consider the following C code snippet and associated build code:
a = 10; b = 5; c = 2; mov [ebp - 4], 10 ; location of variable a mov [ebp - 8], 5 ; location of b mov [ebp - 12], 2 ; location of c
Remember that clicking basically does the following:
sub esp, 4 ; "allocate" space for the new stack item mov [esp], X ; put new stack item value X in
Why local variables are not pushed onto the stack as follows:
push 10 push 5 push 2
instead
sub esp, 12 mov [ebp - 4], 10 ; location of variable a mov [ebp - 8], 5 ; location of b mov [ebp - 12], 2 ; location of c
assembly
chitech
source share