Monday, June 24, 2013

Concepts of Programming Languages 10th Edition : Chapter 10

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review Question

2. Which of the caller or callee saves execution status information?
   => Called.

4. What is the task of a linker?
   => The task of a linker is to find the files that contain the translated subprograms referenced in that program and load them into memory.

6. What is the difference between an activation record and an activation record instance?
   => An activation record is the format, or layout, of the moncode part of a subprogram, whereas an activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

8. What kind of machines often use registers to pass parameters?
   => RISC.

11. What is an EP, and what is its purpose?
    => EP is a point or first address of the activation record instance of the main program. It is required to control the execution of a subprogram.


Problem Set

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation,
   under what circumstances could the value of a local variable in a particular activation retain the value of
   the previous activation?
   => If the variable is declared as static. Static modifier is a modifier that makes a variable history – sensitive.

8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint:Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found(see Section 10.4.2).
   =>  Following the hint stated with the question, the target of every goto in a program could be represented as an address and a nesting_depth, where the nesting_depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting_depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.

9. The static-chain method could be expanded slightly by using two static links in each activation  record instance where the  second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?
   =>  Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.

No comments:

Post a Comment