Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS3723 Homework#2 Scope (28 pts) Use the provided blank answer sheet for your answers. Consider the following C-like code: void main () { int m

CS3723 Homework#2 Scope (28 pts)

Use the provided blank answer sheet for your answers. Consider the following C-like code:

void main()

{

int m = 100;

int i = 101;

int c = 102;

int k = 103;

int e = 104;

int y = 105;

subA();

print("main", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);

void subA()

{

int m = 200;

int x = 1;

subB();

print("subA", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);

void subB()

{

int i = 311;

int c = 312;

m += 20;

x += 5;

k += 10;

subC();

print("subB", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);

void subC()

{

int c = 402;

int k = 403;

int e = 404;

m += 30;

i += x;

if (x

subB();

else

subD();

print("subC", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);

}

}

}

void subD()

{

int y = 505;

m += 50;

i += 50;

k += 50;

e += 50;

print("subD", "m=", m, "i=", i, "c=", c, "k=", k, "e=", e, "y=", y);

}

}

#1 Assume the C-like code uses static scope and main is initially called.

Solve each of the following:

1.1 Show the symbol table for each of the functions Assume int is 4 bytes.

1.2 Trace the code showing the runtime memory stack including environment vectors.

It isn't necessary to show separate copies of the RTMS on each call.

Use these symbols for the activation record addresses in this order:

1.3 What is the output? Make certain you show the output in the correct order.

#2 Assume the C-like code uses dynamic scope and main is initially called.

Solve each of the following:

2.1 Trace the code using dynamic scope. Show the runtime memory stack (it isn't necessary to show separate copies of the RTMS on each call). Do not include an environment vector.

2.2 What is the output? Make certain you show the output in the correct order.

image text in transcribed

image text in transcribed

image text in transcribed

1.1. Symbol tables main subA BA Offset/Address BA Offset/Address subA subD subB subB subC subC subB subD subD 1.1. Symbol tables main subA BA Offset/Address BA Offset/Address subA subD subB subB subC subC subB subD subD

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

Summarize global staffing practices.

Answered: 1 week ago