Question: 2. [20] Consider the following C function long f(long a, long b, long c) When compiled (with Arch gcc), the resulting x86-64 code for the

 2. [20] Consider the following C function long f(long a, long

2. [20] Consider the following C function long f(long a, long b, long c) When compiled (with Arch gcc), the resulting x86-64 code for the function body is addq %rsi, %rdx imu1q% rdx, %rdi salq $63, %rdx sarq $63, %rdx movq %rdi, %rax xorq %rax, %rax Assume that o is in %rdi, b is in %rsi, c is in %rdx, and that %rax is used to hold the return value. Your task is to reverse engineer the C code; specifically, to write a C implementation for the decode function that is functionally equivalent to the compiled x86-64 code above Here are some test runs: f (1, 2, 4) 6 f (3, 5, 7): 36 f (10, 20, 30): 500 Also write a main() function to test your function. Hint: try compiling your C code to x86-64 on Arch using gcc -0g -S3-2.c as you work. Note that the output assembly does not need to match the x86-64 code above exactly -it just needs to be functionally equivalent. Name your source file 3-2.c Zip the source files and solution document (if applicable), name the zip file Assignment3.zip (e.g., EricWillsAssignment3.zip), and upload the zip file to Canvas (see Assignments section for submission link)

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!