Question: Q3. Show the return value of main through register inspection Q4. Issue the following commands: (gdb) list swap_n_add (gdb) disas swap_n_add Group the assembly code



Q3. Show the return value of main through register inspection
Q4. Issue the following commands:
(gdb) list swap_n_add
(gdb) disas swap_n_add
Group the assembly code instructions with their corresponding statements in
swap_n_add
to the best of your ability.
Q5. What is the value of both a1 and a2 before swap_n_add? After? What would be the
value of diff if the call to swap_n_add did not occur?
Part 2:
Now, use breakpoints, and disassembly to solve the following questions. If you understand what the C code is supposed to do, figuring out what the assembly is doing can be done without looking up any opcodes.
Listing for whileLoop.c:
1 int main(){
2 int x = 6;
3 int y = 7;
4 int sum = 0;
5 int i = 0;
6 while(i
7 sum = sum + x;
8 i++;
9 }
10 return sum;
11 }
Q4. Show the lines of assembly that make up the while loop part of the main function.
Specifically highlight the loop test condition.
Q5. Compare the assembly of the whileLoop.c to the same function written with a for loop. What is the difference between them in assembly?
Listing for forLoop.c:
1 int main(){
2 int x = 0;
3 int y = 0;
4 int sum = 0;
5 int i;
6 for(i = 0; i
7 sum = sum + x;
8 }
9 return sum;
10 }
Q6. What is the reason for the “jmp” command?
Listing for N + swap_n_add.c: 1 int swap_n_add (int *xp, int *yp) { 2 int x = *xp;+ int y = *yp;+ 3 44 + 6 7 N 8 } 9+ 12 13 14 *xp = y;* *yp = 10 int main(int argc, char **argv) {* 11 int al = 534;+ int a2 1057;+ int sum = swap_n_add (&a1, &a2);+ int diff = a1 a2; + return sum * diff;* 15 16 17 } X;+ return x + y; Compile swap_n_add and answer the following questions. Include output from gdb to support your answers: - Q1. Put breakpoints at line 7 and line 15 before you run the code within gdb. How many stack frames are there on the stack at each breakpoint? Give the address of each frame:+ Q2.Reconstruct the stack at breakpoint 7, and at 15:
Step by Step Solution
3.39 Rating (161 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
