






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































Layout and allocation of storage locations for named program objects
-^
Mechanism for the target program to access variables
-^
Linkages between procedures
-^
Mechanisms for passing parameters
-^
Interfaces to the operating system for I/O and other programs
Operating system will later map it to physical addresses, decidehow to use cache memory, etc.
Program code
-^
Other static data storage, including global constants and compilergenerated data
-^
Stack to support call/return policy for procedures
-^
int i;
int partition ( int m, int n){^
/* picks a separator v and partitions a[m .. n] so that a[m .. p-1] are less than v,
a[p] = v, a[p+1 .. n] are equal to or greater than v. Returns p.
} void quicksort (int m, int n){^
int i;if ( n > m ){^
i = partition(m,n);
quicksort(m, i-1);
quicksort(i+1, n);
} main ( ){^
readArray ( );a[0] = -9999;
a[10] = 9999;
quicksort (1, 9);
}
temporary values that could not fit into registers
-^
local variables of the procedure
-^
saved machine status for point at which thisprocedure called. includes return address andcontents of registers to be restored.
-^
access link to activation record of previous blockor procedure in lexical scope chain
-^
control link pointing to the activation record of thecaller
-^
space for the return value of the function, if any
-^
actual parameters (or they may be placed inregisters, if possible)
Caller A.R. Callee A.R. TOP-SP
CallerresponsibilityCalleeresponsibility
actual top of stack
10
proc p proc q
C and many C-based languages
Global variables are allocated static storage. Locations are fixed atcompile time.
-^
All other variables must be local to the activation on the top of thestack. These variables are allocated when the procedure is calledand accessed via the TOP-SP pointer.
if procedure p is nested immediately within q in the source code,then the access link of an activation of p points to the more recentactivation of q
case 1: procedure p is at a nesting depth 1 higher than q (can’t bemore than 1 to follow scope rules). Then the access link is to theimmediately preceding activation record (of p) (example quicksortcalls partition)
-^
case 2: recursive call, i.e. q is p itself. The access link in the newactivation record for q is the same as the preceding activation recordfor q (example: quicksort called quicksort)
-^
case 3: procedure p is at a lower nesting depth than q. Thenprocedure p must be immediately nested in some procedure r(defined in r) and there must be an activation record for r in theaccess chain of q. Follow the access links of q to find the activationrecord of r and set the access link of p to point to that activationrecord of r. (partition calls exchange, which is defined in sort)
If the nesting depth of access links getslarge, then access to nonlocal variableswill be inefficient to follow the chainof access links.
-^
Solution is to keep an auxiliary array –the display – in which each element isthe highest activation record on thestack for the procedure at that nestingdepth.
-^
Whenever a new activation record iscreated at level l, it will save the valueof display[l] to restore when it is done
sort q(1,9) saved d[2]
q(1,3) saved d[2]
p(1,3) saved d[3]
e(1,3) saved d[2]
d[1]d[2]d[3] display
stack
In C, this is considered to be a programming error, not one that thecompiler checks for.
serves as the interface between application programs, generated bythe compiler, and the operating system
-^
calls to free and delete can be generated by the compiler, or in somelanguages, explicitly by the programmer
the language Java uses the garbage collector as the deallocationoperation
if there is no space big enough, can request the operating system forvirtual space
-^
if out of space, inform the program
doesn’t reduce the size of space and return to the operating system