计算机代写 COMP1411 Tutorial 06

COMP1411 Tutorial 06
The following exercises are adapted from the textbook.

Question 1.

Copyright By PowCoder代写 加微信 powcoder

Suppose that the following C code
int comp(data_t a, data_t b) {
return a COMP b;
Suppose that a is stored in some portion of register %rdx,
and b is stored in some portion of register %rsi.
The return value is stored in register %al.
For each case below, infer the data type data_t (e.g., char short, int, long, their unsigned versions) and the comparison operator COMP (e.g., <, >, ==, >=, <=, !=) Assembly code Data type data_t Comparison operator COMP cmpl %esi, %edi cmpw %si, %di cmpb %sil, %dil Question 2. In the following C function, the definition of operation OP is missing. # define OP __________ long arith(long x) { return x OP 8; After compilation, we obtain the following assembly code. leaq 7(%rdi), %rax testq %rdi, %rdi cmovns %rdi, %rax sarq $3, %rax Suppose that x is stored in register %rdi. (a) What operation is OP? (b) Annotate the code to explain how it works. Question 3. Convert the following C function to assembly code. long fun(long a, long b) { long result=b; while (b>0) {
result=result*a;
return result;
Assume that a, b, result are stored in registers %rdi, %rsi, %rax, respectively.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com