Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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 swap _n add.c:+ 1 int swap n add(int *xp, int *yp) f 2 int x *xp; int y -*yp; 4- 6 return x + y;- 94 10 int main(int argc, char **argv) {* int al-534; 12 13 int sumswap n add (&a1, &a2) 14 15- 16 17 int a2-1057; int diff = al - a2,- return sum * diff: Compile swap n add and answer the following questions. Include output from gdb to support vour 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

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago