Introduction to Computer Organization with Assembly
Dalhousie University Faculty of Computer Science
Introduction to Computer Organization with Assembly
Assignment 4 Due: 15 Mar 2021, 11:30pm
(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):
x is passed in %rdi, y in %rsi and z in rdx. The return value is stored in % rax. Annotate the assembly code and hence write C code for decode that has the equiv-alent 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.
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.
C code for mystery function. Each instance of (i) represents an unknown variable or expression.
long mystery(long x, long n)
{
long result = (a) ;
long mask;
for (mask = (b); mask (c); mask = (d))
result = (e) ;
return result;
}
2021-03-11