3.2.2.1.1. Stack Allocation And Access
void SomeProcedure (int anArgument)
{
int aVariable;
aVariable = anArgument;
}
SomeProcedure:
push ebp ;save original value of EBP on stack
mov ebp,esp ;store top of stack address in EBP
sub esp,4 ;allocate space for aVariable on stack
mov eax,[ebp+8] ;fetch anArgument into EAX, which is
;8 bytes below the stored top of stack
mov [ebp-4],eax ;store EAX into aVariable, which is
;4 bytes above the stored top of stack
mov esp,ebp ;free space allocated for aVariable
pop ebp ;restore original value of EBP
ret ;return to the caller