cs441f10-ex2-key - Exam 2 Tuesday at 11:00AM CS 441 Fall...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Exam 2 Tuesday, November 23, 2010 at 11:00AM CS 441 Fall 2010 – Sample exam Key Solutions (AW) (For CS 441 use only – do not distribute) A. Run-time storage management Consider the following proc_block program BLOCK START MAIN var x,y,z; procedure A; BLOCK START A var x; { x:=1; y:= x*2 +1 } BLOCK END A procedure B; BLOCK START B var y; procedure C; BLOCK START C var z; procedure D; BLOCK START D var y; { x:= 1.25*z; call A; writeln(x) }; BLOCK END D { z:=1; call A; call D }; BLOCK END C { call C; writeln(x) }; BLOCK END B { x:=0; call B; write(x) }; BLOCK END MAIN Questions a) draw blocks around procedures to indicate the block structure of the program. b) what is the nesting level (largest block number)? c) write the executin history for this program in the form: d) draw the call graph for this program (a tree of calls). e) draw the stack of activation records for two cases: (i) directly after C calls A (ii) directly after D calls A f) what is the output (writeln) from the program assuming the static scoping? What is the output assuming dynamic scoping? Assume that the execution starts at location 900, the end of code
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
for main is at 200, for A at 300, for B at 400, for C at 500 and for D at 600. Answer: solutions to problem A are in http://www.cs.uky.edu/~jurek/cs441/cs441f10/hw/hw7help.pdf B. Code Generation Write (by hand) P-stack code for the following program: { int i; procedure proc1(){ int a,b; { i:= 12; a:=10; if (a < i ) { b:= a+i}; b:= i + a; i:= i + a * b; }; } { call proc1(); write(i);}; } ANSWER: 001 Prog 1 073 004 Proc 2 007 ; #local var and the beginning of the proc 007 I_Variable 1 3 ; @i (i is non-local, REL_BLK_LEV = 1, OFF = 3) 010 I_Variable 0 3
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

cs441f10-ex2-key - Exam 2 Tuesday at 11:00AM CS 441 Fall...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online