Question: Can someone answer and explain how or why for these problems? Thanks! __________________________________________________________________________ Suppose the C function foo has been compiled into LC-3 assembly. Consider

Can someone answer and explain how or why for these problems? Thanks!

__________________________________________________________________________

Suppose the C function foo has been compiled into LC-3 assembly. Consider the following

fragment of resulting assembly instructions:

FOO : ADD R6 , R6 , # -1

ADD R6 , R6 , # -1

STR R7 , R6 , #0

ADD R6 , R6 , # -1

STR R5 , R6 , #0

ADD R5 , R6 , # -1

ADD R6 , R6 , # -4

How many local variables does foo have?

_____________________________________________

Consider the following C program :

# include < stdio .h >

int foo(int);

int bar(int);

int main() {

int a = 1, b = 2;

a = foo(a);

b = bar(b);

printf(" a : %d , b : % d \ n ", a, b);

return 0;

}

int foo(int x) {

int y = 2;

return y + x;

}

int bar(int x) {

int z;

return z + x;

}

What is the(expected) printed output of this program ? Draw the runtime stack.

What is the value of the local variable z when bar begins executing ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!