C Programming Question

(1) A function with prototype

long decode(long x, long y, long z);
Has the following assembly code from gcc (Note that the line numbers in the first
column have no functional value, but are supplied to help):
1. decode:
2. subq %rdi, % rsi
3. imulq %rsi, %rdi
4. movq %rsi, %rax
5. salq $63, %rax
6. sarq $63, %rax
7. xorq %rdi, %rax
8. ret
(a) Annotate the assembly code.
(b) Hence write C code for decode that has the equivalent effect to the assembly
code.
(2) • The assembly code below was generated by compiling the C code given below
the assembly code.
• Annotate the assembly code and find the values for the missing parts of the C
code as indicated by the ‘(i)’ and then answer the following questions:
(a) Which registers hold the values for: x, n, result, and mask? (assume the 64-bit
register identifier in each case.)
(b) Complete the table below (next page) in order to identify the missing C ex-
pressions and the line of assembly code at which each C expression is defined.
Give reasons for your answer.
Assembly code for mystery function. Note that the line numbers in the first
column have no functional value, but are supplied to help you answer the assignment.
1. loop:
2. movl %esi, %ecx
3. movl $1, %edx
4. movl $0, %eax
5. jmp .L2
6. .L3:
7. movq %rdi, %r8
8. andq %rdx, %r8
9. orq %r8, %rax
10. salq %cl, %rdx
11. .L2:
12. testq %rdx, %rdx
13. jne .L3
14. rep; ret
1

 

attachment_1
attachment_2
attachment_3
Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.