# Consider the following segment of code:procedure Mvar x: integer;procedure A (c: integer)var a, b: integer;procedure Bvar b, c, d: integer;begin {B}….a := c – d;….end B;begin {A}….x := b + c;….B()….end A;begin {M}….A(3)….end M;Assuming the definition of M is at static nesting level 0. Draw the runtime stack that will be ineffect at the execution of “a := c – d;”. Show the static and dynamic links, and the currentpositions of the EP and SP pointers.What is the static distance to x’s environment of definition and the offset within the environmentwhen “a := c – d;” is executed?

Question
89 views

Consider the following segment of code:
procedure M
var x: integer;
procedure A (c: integer)
var a, b: integer;
procedure B
var b, c, d: integer;
begin {B}
….
a := c – d;
….
end B;
begin {A}
….
x := b + c;
….
B()
….
end A;
begin {M}
….
A(3)
….
end M;
Assuming the definition of M is at static nesting level 0. Draw the runtime stack that will be in
effect at the execution of “a := c – d;”. Show the static and dynamic links, and the current
positions of the EP and SP pointers.
What is the static distance to x’s environment of definition and the offset within the environment
when “a := c – d;” is executed?

check_circle

Step 1

Instructions for drawing the runtime stack (at “a:= c-d;”):

• The stack includes the activation records of the nested procedures.
• The dynamic link of a procedure always points to the caller procedure.
• The static link of a procedure points to the most recent occurrence of an activation record of the static parent of the procedure being called.
• The EP or FP points to the frame base of the current caller.
• The SP points to the next available stack location.
Step 2

The runtime s...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Computer Science 