Question
Problem #4. C language, Stack Data Placement, Pointers Consider the following C program. Assume that the register SP at the beginning points to 0x1100. Answer
Problem #4. C language, Stack Data Placement, Pointers
Consider the following C program. Assume that the register SP at the beginning points to 0x1100. Answer the following questions. Assume all variables are allocated on the stack, and in the order as they appear in the program. ASCII code for character 0 is 48.
1 | int main( void ) { |
2 | volatile unsigned long int a = 25; |
3 | volatile int c = -2, d = 2; |
4 | volatile char mych = {0, 1, 2, 4}; |
5 | volatile unsigned long int *lpa = &a; |
6 | volatile int *pi = &d; |
7 | lpa = lpa - 2; // |
8 | *lpa = *lpa + 260; // |
9 | pi++; // |
10 | *pi = *pi + c; // |
11 | } |
Fill in the following table by determining the values/addresses given below.
# | Question? | Value/Address |
1 | The number of bytes allocated on the stack for the variable declared in line 2. |
|
2 | The number of bytes allocated on the stack for the character array declared in line 4. |
|
3 | The number of bytes allocated on the stack for all variables declared in lines 2-6. |
|
4 | Value of mych[0] after initialization performed in line 4. |
|
5 | Address of variable a (&a). |
|
6 | Address of character array mych |
|
7 | Address of variable d (&d) |
|
8 | Value of lpa at the moment after the statement in line 7 is executed. |
|
9 | Value of *lpa at the moment after the statement in line 8 is executed. |
|
10 | Value of mych[0] at the moment after the statement in line 8 is executed. |
|
11 | Value of pi at the moment after the statement in line 9 is executed. |
|
12 | Value of *pi at the moment after the statement in line 10 is executed. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started