c - Stack / base pointers in assembly -
i know topic has been covered ad nauseam here, , other places on internet - question simple 1 try head around assembly...
so if understand correctly ebp (base pointer) point top of stack, , esp (stack pointer) point bottom -- since stack grows downward. esp therefore points 'current location'. on function call, once you've saved ebp on stack insert new stack frame - function. in case of image below, if started n-3 go n-2 function call. when @ n-2 - ebp == 25 , esp == 24 (at least initially, before data placed on stack)?
is correct or off on tangent here?
thanks!
this depends upon not hardware architecture , compiler, calling convention, agreed-upon way in functions work stack call 1 another. in other words, there different orders in function can push things onto stack, depending on compiler settings (and peculiar #pragma
options, etc, etc).
it looks talking cdecl
calling convention on x86 architecture. in case, caller's ebp
pushed onto stack after return address. so, in example's n-2, location 25 contain pointer calling function n-3 (ie, contain address of instruction after call
got n-2) , location 24 contain old ebp
, , esp = 23 after call, before locals have been pushed onto stack. (except compilers make space on stack after call, , esp 20 instead of moving , down inside function n-2.)
however aware on x86 there particular optimization compiler can called frame pointer omission, avoids pushing old ebp
onto stack altogether under conditions.
Comments
Post a Comment