Question: Using the stack diagram found in the above file, hand trace the code given in our Lab 4 ( main . c , main.s ,

Using the stack diagram found in the above file, hand trace the code given in our Lab 4(main.c, main.s, p1.c, p1.s, p2.c and p2.s) using the test case, i.e., x =6, y =9, buf[40] and reflect the result of your hand tracing on this stack diagram.
Note: Hand trace the entire program until you reach (but have not yet executed) the ret instruction of the main function.
The use of the Register Table is optional: use it only if you find it useful. You do not have to include it as part of your answer to this question.
As you are hand tracing and updating the stack diagram, make sure you attend to the following details:
Indicate the movement of %rsp along the left-hand side of the stack diagram (under the column named Base + Displacement) by crossing its old location and rewriting %rsp to indicate its new location (as we have done in our lectures and in Lab 4).
Strikethrough the content of the stack that has been popped and/or dealt with.
When updating the content of a stack location, strikethrough its old value and write the new value in the same stack location.
Include the content of buf[], i.e., the actual value stored in buf[], in your stack diagram. Do not simply write buf[] over this section of the stack as we did in Lab 4. This will help you answering the question in Part 2. Remember that each character is a byte.
Draw a line just below each stack frame to clearly indicate where each of them ends. Also, under the column named Purpose on the right-hand side, label each stack frame using the name of its associated function.
When drawing your stack diagram, you do not have to show the effect on the stack of the five (5) call instructions at Line 33, Line 43, Line 45 and Line 57 in main.s and at Line 47 in p1.s. These are calls to printf(...), puts(...) and sprintf(...). In other words, you do not have to add the return addresses associated with these five (5) calls onto the stack.
Part 2
In this second part, we shall investigate what happens to the canary value when we change the size of the array called buf[].
Modify the code in main.c by reducing the size of buf[] from 40 down to 24 as you did in Lab 4. Compile and execute this modified program. What happens?
On the second page of the file you downloaded in Part 1(the file containing the stack diagram) answer the question: What happens to the canary value when you reduce the size of buf[] from 40 down to 24, and x =6, y =9?
To figure out what happens, you can hand trace the assembly code of this modified program creating a second drawing of the stack diagram. If you follow the instructions in Part 1 and attend to details as you are drawing this second stack diagram, it should reveal what is happening to the canary value. Note that you do not have to include this second stack diagram to your answer for this question./*
* Filename: main.c
*
* Description: Test driver for our Lab 4.
*
* Auhtor:
* Modification date: Feb. 2024
*/
#include
void proc1(char *, int *, int *);
void main(){
char buf[40];
int x =6;
int y =9;
printf("Original values are: x=%d, y=%d.
", x, y);
proc1(buf, &x, &y);
printf("Final values are: x=%d, y=%d.
", x, y);
puts(buf);
return;/*
/*
* Filename: p1.c
*
* Description: p1.c for our Lab 4.
*
* Auhtor:
* Modification date: Feb. 2024
*/
#include
int proc2(int, int);
void proc1(char *s, int *a, int *b){
int v;
int t;
t =*a;
v = proc2(*a,*b);
sprintf(s, "The result of proc2(%d,%d) is %d.",*a,*b, v);
*a =*b -2;
*b = t;
return;
}/*
* Filename: p2.c
*
* Description: p2.c for our Lab 4.
*
* Auhtor:
* Modification date: Feb. 2024
*/
int proc2(int m, int n){
int res;
res = m*n -12;
return res;
}
 Using the stack diagram found in the above file, hand trace

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!