Question
The assembly code on the top came from the skeleton C file on the bottom after optimizing with -O0. gcc -O0 -S -fno-asynchronous-unwind-tables .file hwk4.c
The assembly code on the top came from the skeleton C file on the bottom after optimizing with -O0.
gcc -O0 -S -fno-asynchronous-unwind-tables
.file "hwk4.c" .text .section .rodata .LC0: .string "%d " .text .globl main .type main, @function main: endbr64 pushq %rbp movq %rsp, %rbp subq $32, %rsp movl $-672816143, -12(%rbp) movl $8, -8(%rbp) movl $0, -20(%rbp) movl $0, -4(%rbp) movl $1, -16(%rbp) jmp .L2 .L4: movl -16(%rbp), %eax sall $2, %eax movl -12(%rbp), %edx movl %eax, %ecx sarl %cl, %edx movl %edx, %eax andl $15, %eax movl %eax, -4(%rbp) movl -4(%rbp), %eax cmpl -8(%rbp), %eax jle .L3 addl $1, -20(%rbp) .L3: addl $2, -16(%rbp) .L2: cmpl $8, -16(%rbp) jle .L4 movl -20(%rbp), %eax movl %eax, %esi leaq .LC0(%rip), %rdi movl $0, %eax call printf@PLT movl $0, %eax leave ret
------------------------------------------------------------------------------------------------------------
#includeint main() { int c=______(A)_____; int n=______(B)_____; int count = 0; int digit = 0; int i; for (i=1;____(C)___; ___(D)___){ digit = (____(E)____>> (i<<2)) ___(F)___; if(digit ____(G)____ n) count++; } printf("%d ",count); }
--
1.1 Map the assembly address/register to the variables
-20(%rbp)
-16(%rbp)
-12(%rbp)
-8(%rbp)
-4(%rbp)
1.2 From the C code skeleton and answer what C could could/should go in the blanks
a.
b.
c.
e.
f.
g
Q2 Determine the result of the following operations and state where the result is stored.
Consider the following initial values for the registers and memory. Values are reset back to the values shown in the table before each operation. Determine the result of the following operations and state where the result is stored.
Destination should be formatted after doing all address calculations in order to be counted for full credit
Result should match the size specified by the destination
Register | Value |
---|---|
%rax | 0xFEDCBA9876543210 |
%rbx | 0x0000000012345678 |
%r8 | 0xFFFFFFFFFFFFFFFE |
Memory Address | Value |
---|---|
0xFEDCBA9876543209 | 0xC3 |
0xFEDCBA987654320A | 0xA8 |
0xFEDCBA987654320B | 0x2B |
0xFEDCBA987654320C | 0x98 |
0xFEDCBA987654320D | 0x7D |
0xFEDCBA987654320E | 0x02 |
0xFEDCBA987654320F | 0x4C |
0xFEDCBA9876543210 | 0x64 |
0xFEDCBA9876543211 | 0x38 |
0xFEDCBA9876543212 | 0x91 |
0xFEDCBA9876543213 | 0x7A |
0xFEDCBA9876543214 | 0x23 |
0xFEDCBA9876543215 | 0x61 |
0xFEDCBA9876543216 | 0xAB |
0xFEDCBA9876543217 | 0xCF |
0xFEDCBA9876543218 | 0x3F |
0xFEDCBA9876543219 | 0x19 |
0xFEDCBA987654321A | 0xD3 |
2.1 Given the command, State the destination and the result
Command: decl %ebx
Destination:
Result:
2.2 Given the command, State the destination and the result
Command: incb 9(%rax)
Destination:
Result:
2.3 Given the command, State the destination and the result
Command: negq %rax
Destination:
Result:
2.4Given the command, State the destination and the result
Command: xorq %rbx,%rax
Destination:
Result:
2.5 Given the command, State the destination and the result
Command: sarl $3, %ebx
Destination:
Result:
2.6 Given the command, State the destination and the result
Command: xorw $5, -0x4(%rax)
Destination:
Result:
2.7 Given the command, State the destination and the result
Command: subw -6(%rax),%bx
Destination:
Result:
2.8 Given the command, State the destination and the result
5 Points
Grading comment:
Destination:
Result:
2.9 Given the command, State the destination and the result
Command: movw 12(%rax,%r8,4),%ax
Destination:
Result:
2.10 Given the command, State the destination and the result
Command: movb 2(%rax,%r8,2), %bl
Destination:
Result:
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