Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q)Consider the following structure declaration containing a structure within a structure, and answer the following questions. struct person{ struct size{ int height; int weight; }s;

Q)Consider the following structure declaration containing a structure within a structure, and answer the following questions.

struct person{

struct size{

int height;

int weight;

}s;

int *hp;

int games[2];

}person1, person2;

How many total bytes does the structure require?

height

weight

hp

games[0]

games[1]

What are the offsets in bytes of the following fields?

s.height: ______________

hp:_______________

games[1]:______________

The compiler generates the following assembly code for the body of str_init (shown below).

movq 16(%rbp), %rax //Get p1 into register %rax

movl 4(%rax), %edx //Get p1->s.weight store in register %edx

movq 16(%rbp), %rax //Get p1 into register %rax

movl %edx, (%rax) //Store in p1->s.height

movq 16(%rbp), %rax //Get p1 into register %rax

leaq 4(%rax), %rdx //Compute address of p1->s.weight in register %rdx

movq 16(%rbp), %rax //Get p1 into register %rax

movq %rdx, 8(%rax) //Store in p1->hp

On the basis of this information, fill in the missing expressions in the code for str_init.

void str_init(person *p1)

{

p1->s.height = _____________;

p1->hp = _________________;

}

How would you call str_init with the struct person1 passed to it?

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions