Chat with us, powered by LiveChat GSP 215 Week 3 Homework Representing and Manipulating Information NEW | Writedemy

GSP 215 Week 3 Homework Representing and Manipulating Information NEW

GSP 215 Week 3 Homework Representing and Manipulating Information NEW

GSP 215 Week 3 Homework Assignment

 

Week 3 Homework—Representing and Manipulating Information

 

Structures are a mechanism for creating a data type to aggregate multiple objects into a single unit. All the components of a structure are stored in a contiguous region of memory and a pointer to a structure is the address of its first byte. To access the fields of a structure, the compiler generates code that adds the appropriate offset to the address of the structure.

The example on the book on page 242 shows the following structure.

struct rec {

            int i;

            int j;

            int a[3];

            int *p;

};

This structure contains four fields: two 4-byte int’s, an array consisting of three 4-byte int’s, and a 4-byte int pointer giving a total of 24 bytes. j is offset 4 bytes.

    0                          4                          8                     16                      20                      24

i j a[0] a[1] a[2] p

 

Assuming variable 4 is of type struct rec * and is in register %edx, the following code copies element r->i to element r->j.

movl  (%edx), %eax    // Get r->i

movl %eax, 4(%edx) //Store r->j  To store into the field j, the code adds offset 4 to the address of r

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;

1.      How many total bytes does the structure require?

         
height weight hp games[0] games[1]

 

2.      What are the offsets in bytes of the following fields?

s.height: ______________

      hp:_______________

   games[1]:______________

 

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

 

4.      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 = _________________;

}

5.      How would you call str_init with the structperson1 passed to it? 

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order