Question: Problem 1. A C header file hw4prob.h contains the following declarations: struct foo { int a; int b; }; void fun(struct foo fp, int n

 Problem 1. A C header file hw4prob.h contains the following declarations:

Problem 1. A C header file hw4prob.h contains the following declarations: struct foo \{ int a; int b; \}; void fun(struct foo fp, int n ); Running gcc on the code (with 0g ) generates the following assembly code for fun: (fp in \%rdi, n in \%esi): fun: movl $0,% edx movl $0,% eax .L2: cmpl \%esi, \%eax jge . L4 movslq \%eax, \%rcx leaq (\%rdi, %rrcx,8),%rrcx addl (%rcx),%edx mov1 \%edx, 4(%rrcx) addl $1,% eax jmp .L2 .L4 : ret Answer the following questions: a. Note that the function does not return a value. So what is \%eax used for? b. What is stored in register \%edx? c. Reproduce the body of fun. Hint: the instruction movslq ("move with sign extension long to quadword") takes the source 4-byte longword (int) and copies it to the destination quadword, sign-extending it in the process (i.e., the added 32 bits are copies of the original sign bit). d. Give a high-level description of what this function does

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!