Después de que he leído sobre la función y la pila de http://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames Tengo una pregunta acerca de las variables locales.
Instantánea del artículo:
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
Esto significa que las variables locales se puede acceder haciendo referencia ebp. Considere el siguiente fragmento de código C y el correspondiente código de montaje:
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
Recuerde que empujar básicamente hace lo siguiente:
sub esp, 4 ; "allocate" space for the new stack item
mov [esp], X ; put new stack item value X in
¿Por qué son las variables locales no empuja en la pila de la siguiente manera:
push 10
push 5
push 2
en lugar de
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
Puede hacerlo en boats, ¡pero tenga cuidado con el orden! –
Es sub esp, 4 - mov [esp], 10 no es igual a mov [ebp-4], 10? – chitech