Question
A) (20 Points) After executing each of the following x86-64 Assembly code snippets, (1) what is the content of the rax register in hex (show
A) (20 Points) After executing each of the following x86-64 Assembly code snippets, (1) what is the content of the rax register in hex (show your calculations/work in hex). (2) what is the status of each of the four flags (ZF, SF, CF, and OF) and why? Explain each flag status/state in details (i.e., discuss reasons why each of those flags is set, cleared, or unaffected). Assume that the initial value stored in rax prior to executing each of the following code snippets is 0. 1) movw $0x7DD7, %ax addw $0x5CC9, %ax 2) movl $0x0F3B, %eax addb $0x9C, %al 3) movl $0xDE003A, %eax subw $60, %ax 4) movl $-0x47, %eax subb $58, %al 5) movl $0x7FFF, %rax incb %ah 6) movl $0xFF00A7, %rax movw $0x0013, %bx imulw %bx, %ax 7) movabsq $0xFFFF3FFF, %rax shrw $15, %ax 8) movl $0xFFFF00D9, %rax sarb $5, %al 9) movl $0xFFFF00, %rax andw $0xFF, %ax 10) movq $0x000000F5, %rbx movl $5, %rsi leaw 0xFF(%rbx, %rsi, 2), %ax
B) (15 Points) Consider the following 5 x86-64 assembly code snippets. Each of those snippets is generated by a particular version of GCC with particular settings of the command-line options. For each part: (1) Briefly explain each assembly instruction inside the snippet and its effect. (2) What is the content of the rax register (in hexadecimal) right after this entire code snippet is executed? Assume that the initial value stored in rax prior to executing each of the following code snippets is 0. (3) This assembly code snippet was part of assembly code that was generated by compiling C code with the following form: foo() { ________ var1 = ____ ; // the numerical value assigned to var1 here must be in decimal ________ var2 = ( __________ ) var1; } Assuming this is the only code inside the dummy function foo, fill in all missing parts of the C code inside this function. 1) movb $-16, -5(%rbp) movzbl -5(%rbp), %eax movl %eax, -4(%rbp) 2) movb $0x88, -3(%rbp) movsbw -3(%rbp), %ax movw %ax, -2(%rbp) 3) movw $0x7FFF, -6(%rbp) movswl -6(%rbp), %eax movl %eax, -4(%rbp) 4) movb $0x9C, -9(%rbp) movsbq -9(%rbp), %rax movq %rax, -8(%rbp) 5) movl $-2, -8(%rbp) movl -8(%rbp), %eax movl %eax, -4(%rbp) C) (5 Points) Consider the following x86-64 assembly code generated by a particular version of GCC with particular settings of the command-line options: loop: movl %esi, %ecx movl $1, %edx movl $0, %eax jmp .L2 .L3: movq %rdi, %r8 andq %rdx, %r8 orq %r8, %rax salq %cl, %rdx .L2: testq %rdx, %rdx jne .L3 ret
This assembly code was generated by compiling C code that had the following form: long loop(long x, long n){ long result = _______ ; long mask; for(mask = ________ ; mask ________ ; mask = _________ ){ result |= ______ ; } return result; } 1. Which registers hold program values x, n, result, and mask? 2. What are the initial values of result and mask? 3. What is the test condition for mask? 4. How does mask get updated? 5. Fill in all missing parts of the C code above.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started