






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the university of michigan covers the concepts of storage classes, storage class selection, distinct regions of memory, memory organization, variable binding, static allocation, heap allocation, accessing static/heap variables, run-time stack, stack pointers, and stack frame construction. It also includes examples and problem-solving exercises.
Typology: Study notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!























y
Doesn’t support pointer access!
Code
Static Data
Stack^ Heap
Code and static data sizes determined by the compiler Stack and heap sizes vary at run-time
Stack grows downward Heap grows upward
Some ABI’s have stack/heap switched
int count (int n) {
static int sum = 0; sum += n;
sum has local visibility coupled with a global lifetime
lots of bugs!
y
Assigned by linker
y
Same for branch addresses
» Represents execution environment of the function
y
Per invocation! Recursive function – each dynamic call hasits own frame
» Includes: local variables, parameters, return value,
temporary storage (register spill)
» Push frame of f on stack when program calls f » Pop stack frame when f returns » Top frame = fame of currently executing function
Prev Frame
Top Frame
stackgrows
Param 1... Param n
Return address^ Previous FP
Local 1... Local n
Temp 1... Temp nParam 1... Param n
Return address
Outgoing parameters Incoming parameters
Current frame responsibility of the callee
Previous frame responsibility of the caller
For the following program: int foo(int a) {
int x; if (a = 1) return 1; x = foo(a-1) + foo(a-2); return (x);
} main() {
int y, z = 10; y = foo(z);
Problem for languages withnested functions (Pascal,ML): How do we accesslocal variables from otherframes?
Need a static link: a pointerto the frame of the enclosingfunction
»
Defined away in C as C hasonly a 2 level binding
Previous FP = dynamic link,ie, pointer to the previousframe in the currentexecution
Previous FP
Local 1... Local n
Temp 1... Temp nParam 1... Param n
Return address
Static link
» Push each actual parameter » Push caller-saved registers » Push static link (if necessary) » Push return address (current PC) and jump to caller
code
» Push dynamic link (ie FP) » Old stack pointer becomes new frame pointer » Push callee-saved registers » Push local variables