Stack frames & static predecessors

Till Wollenberg <>
Fri, 24 Aug 2007 02:10:32 +0200

          From comp.compilers

Related articles
Stack frames & static predecessors (Till Wollenberg) (2007-08-24)
Re: Stack frames & static predecessors (2007-08-24)
Re: Stack frames & static predecessors (glen herrmannsfeldt) (2007-08-24)
Re: Stack frames & static predecessors (Tomasz Kowaltowski) (2007-08-24)
Re: Stack frames & static predecessors (Paolo Bonzini) (2007-08-24)
Re: Stack frames & static predecessors (Gene) (2007-08-24)
Re: Stack frames & static predecessors (2007-08-25)
[4 later articles]
| List of all articles for this month |

From: Till Wollenberg <>
Newsgroups: comp.compilers
Date: Fri, 24 Aug 2007 02:10:32 +0200
Organization: Compilers Central
Keywords: Pascal, code, question, comment
Posted-Date: 23 Aug 2007 20:47:53 EDT


I'm currently preparing for an exam in 'compiler construction' and
wondered how the following problem is solved in real world compilers:
if some code of an inner function ('bar') accesses a local variable
('x') of an outer function ('foo') how is the address (on the stack)
of this variable determined?

The variable is stored in the stack frame of the outer function
(static predecessor of bar), but as far as I can see the callee does
only have a pointer to the stack frame of its dynamic predecessor. Due
to the recursion bar cannot 'know' where the stack frame of foo
actually is.

(I choose Pascal for my example because it needs a language which
supports nested functions.)

| program example;
| procedure foo;
| var x: integer;
| procedure bar(n: integer);
| begin
| if (n < 5) then bar(n + 1) else writeln(x);
| end;
| begin
| x:=456;
| bar(1);
| end;
| begin.
| foo;
| end;

Best regards, Till.

real email: wollenberg (at) web (.dot.) de
[The calling procedure passes in pointers to the stack frames of all
of the lexically enclosing procedures, a structure known as a display.
The code to create the display at each call point is tedious but not
complex, and the techniques have been known since Algol 60, if not
longer. This used to be a standard topic in compiler texts, at least
until the academic world switched from Pascal to C. Take a look at the
x86 ENTER instruction, which is specifically designed to create stack
frames with displays. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.