(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):
2. subq %rdi, % rsi
3. imulq %rsi, %rdi
4. movq %rsi, %rax
5. salq $63, %rax
6. sarq $63, %rax
7. xorq %rdi, %rax
(a) Annotate the assembly code.
(b) Hence write C code for decode that has the equivalent effect to the assembly
(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.
2. movl %esi, %ecx
3. movl $1, %edx
4. movl $0, %eax
5. jmp .L2
7. movq %rdi, %r8
8. andq %rdx, %r8
9. orq %r8, %rax
10. salq %cl, %rdx
12. testq %rdx, %rdx
13. jne .L3
14. rep; ret