Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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: 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started