Java Reference
In-Depth Information
4. Consider the following C-like program that allows subprograms to nest.
Show the sequence of frames, with static links, on the stack when r(16)
is executed assuming we start execution (as usual) with a call to main().
Explain how the values of a, b,andc are accessed in r's print statement.
p(int a){
q(int b){
r(int c){
print(a+b+c);
}
r(b+3);
}
s(int d){
q(d+2);
}
s(a+1);
}
main(){
p(10);
}
5. Reconsider the C-like program shown in Exercise 4, this time assuming
display registers are used to access frames (rather than static links).
Explain how the values of a, b,andc are accessed in r's print statement.
6. Consider the following C function. Show the content and structure of
f's frame. Explain how the o
ff
sets of f's local variables are determined.
int f(int a, int b[]){
inti=0,sum=0;
while (i < 100){
int val = b[i]+a;
if (b[i]>b[i+1]) {
int swap = b[i];
b[i] = b[i+1];
b[i+1] = swap;
} else {
int avg = (b[i]+b[i+1])/2;
b[i] = b[i+1] = avg; }
Search WWH ::




Custom Search