HW4 -- Due 6/04/97 1) Consider the following program written in a ALGOL-like language: procedure BLAH; integer GLOBAL; integer array LIST[1:2]; procedure FOO (PARAM); integer PARAM; begin PARAM := 3; GLOBAL := GLOBAL + 1; PARAM := 5 end; begin LIST[1] := 3; LIST[2] := 1; GLOBAL := 1; FOO (LIST(GLOBAL)) end; Hand execute the program under the following assumptions, and compare the resulting values in the array LIST in BLAH after the return from FOO. a) Parameters are passed by value. b) Parameters are passed by reference. b) Parameters are passed by name. b) Parameters are passed by value-result. 2) FORTRAN allows a subprogram to have multiple entry points. Why is this sometimes a valuable capability ? 3) Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following skeletal program: procedure BLAH; procedure A; procedure B; begin {B} ... <------------ 1 end; {B} procedure C; begin {C} ... B; ... end; {C} begin {A} ... C; ... end; {A} begin {BLAH} ... A; ... end; {BLAH} 4) For the skeletal program in Problem 3, show the display that would be active at position 1, along with the activation records on the stack. 5) Show the stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following skeletal program: procedure BLAH; procedure C; forward; procedure A (FLAG : boolean); procedure B; begin {B} ... A (false) end; {B} begin {A} if FLAG then B else C ... end; {A} procedure C; procedure D; begin {D} ... <--------------- 1 end; {D} begin {C} ... D; ... end; {C} begin {BLAH} ... A(true); ... end; {BLAH} The calling sequence for this program for execution to reach D is BLAH calls A A calls B B calls A A calls C C calls D Show the local variables as part of the activation.