From: Stuart M. <stu...@st...> - 2002-04-24 12:29:13
|
Adrian The frame pointer is used when stack contains objects of unknown size, for example variable size arrays, or when alloca() is used. It is also used sometimes when setting up the parameters for functions which take a large number of parameters. In this case the stack will look something like: higher address |caller's stack +------------------ |parameters | |local variables +------------------ <- frame pointer | |dynamic data | +------------------ <- stack pointer lower address Normally the compiler uses the offset from the stack pointer to reference local variables. However when there is dynamic data, the compiler cannot use the stack pointer because it doesn't know at compile time the size of the dynamic data. So what the compiler will do, when it detects this situation, is after moving the stack pointer down to make room for the local variables, it copies the stack pointer into the frame pointer, and from then on reference local variables and parameters through the frame pointer. The stack pointer is now used only for allocating dynamic data and making further function calls. In theory the compiler only need to do this when dynamic data is being used, but in practice it makes backtracing through code easier if the frame pointer is always used. So you'll frequently see code which stores the frame pointer on the stack, and copies stack pointer to frame pointer on entry to a function, and then never uses it, simply because it makes backtracing easier for debugger. Stuart On Tue, 23 Apr 2002 23:27:07 +0100 ad...@mc... wrote: > On Tuesday 23 Apr 2002 11:40 am, Stuart Menefy wrote: > > Adrian > > > > This is something I wrote a while ago when somebody asked the same question > > (I assume were talking gcc here). > > > > Stuart, > > Thanks very much for this - very helpful and already the dissasembly is > beginning to make sense - but what is the frame register (r14) - ie what is > it's function. > > This is not a term I've coem across before and I cannot find it referenced in > the Hitachi programming manual. > > Thanks, > > Adrian -- Stuart Menefy stu...@st... STMicroelectronics Ltd ST Intranet: mo.bri.st.com Bristol, UK Rest of the World: www.linuxsh.st.com |