Nachdem ich über Funktion gelesen haben und Stapel von http://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames habe ich eine Frage über lokale Variablen.
Snapshot aus dem Artikel:
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
Dies bedeutet, lokale Variablen durch Bezugnahme auf EBP zugegriffen werden kann. Betrachten Sie das folgende C-Code-Fragment und entsprechenden Assembler-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
Denken Sie daran, dass im Grunde tut drückt dies:
sub esp, 4 ; "allocate" space for the new stack item
mov [esp], X ; put new stack item value X in
Warum sind lokale Variablen nicht drücken in den Stapel wie folgt aus:
push 10
push 5
push 2
statt
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
Sie können auf Boath Wege tun, aber seien Sie vorsichtig mit der Reihenfolge! –
Ist sub esp, 4 - mov [esp], 10 nicht gleich mov [ebp-4], 10? – chitech