6.4 Nested procedure and functions

When a routine is declared within the scope of a procedure or function, it is said to be nested. In this case, an additional invisible parameter is passed to the nested routine. This additional parameter is the frame pointer address of the parent routine. This permits the nested routine to access the local variables and parameters of the calling routine.

The resulting stack frame after the entry code of a simple nested procedure has been executed is shown in table (6.4).


Table 6.4: Stack frame when calling a nested procedure (32-bit processors)



Offset from frame pointerWhat is stored


+x parameters
+8 Frame pointer of parent routine
+4 Return address
+0 Saved frame pointer