CSCI 2122 - Systems Programming - A3 Introduction to Computer Organization with Assembly


  • 作业标题:CSCI 2122 - Systems Programming - A3 Introduction to Computer Organization with Assembly
  • 课程名称:Dalhouse University CSCI 2122 Systems Programming
  • 完成周期:2天

1. Description

(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 expressions 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

C code for mystery function. Each instance of (i) 2 fa; b; c; d; eg 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;
}

。。。


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录