Question: 1?For a function with prototype long decode2(long x, long y, long z); gcc generates the following assembly code: decode2: movq %rdi, %rax subq %rdx, %rax

1?For a function with prototype

long decode2(long x, long y, long z);

gcc generates the following assembly code:

decode2: movq %rdi, %rax subq %rdx, %rax imulq %rax, %rdi salq $63, %rax sarq $63, %rax xorq %rdi, %rax addq %rsi, %rax ret

Parameters x, y, and z are passed in registers %rdi, %rsi, and %rdx. The code stores the return value in register %rax. Reverse-engineer decode2. (In other words, write C code for decode2 that will have an effect equivalent to the assembly code shown.)

2?Implement function sum() that takes as input an array of integers a and an integer n, sums up the first n integers of array a, and returns the sum.

3?After completing the first two problems, open the file assignment4.s, find the assembly code corresponding to function sum from problem 2, and then find the assembly instructions corresponding to the body of the for loop you implemented in function sum. Write the assembly instructions you found AS A COMMENT in file assignment4.c.

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!