Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using a 64-bit machine will result in incorrect answers, because the function calling conventions are different (parameters are often passed in registers). Listing for swap_n_add.c:

Using a 64-bit machine will result in incorrect answers, because the function calling conventions are different (parameters are often passed in registers).

Listing for swap_n_add.c:

1 int swap_n_add(int *xp, int *yp) {

2 int x = *xp;

3 int y = *yp;

4

5 *xp = y;

6 *yp = x;

7 return x + y;

8 }

9

10 int main(int argc, char **argv) {

11 int a1 = 534;

12 int a2 = 1057;

13 int sum = swap_n_add(&a1, &a2);

14 int diff = a1 - a2;

15

16 return sum * diff;

17 }

Compile swap_n_add and answer the following questions. Include output from gdb to support your answers:

a. 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:

b.Reconstruct the stack at breakpoint 7, and at 15:

Line 7:

Pointers

(Register Addresses)

EBP Offset

Address

Name

Description

Value

ebp - 16

ebp - 12

ebp - 8

ebp - 4

ebp

ebp + 4

ebp + 8

ebp + 12

Line 15:

Pointers

(Register Addresses)

EBP Offset

Address

Name

Description

Value

ebp - 24

ebp - 20

ebp - 16

ebp - 12

ebp - 8

ebp - 4

ebp

ebp + 4

ebp + 8

ebp + 12

c. Show the return value of main through register inspection

d. 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.

e. 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?

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago