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 Complete the

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

Complete the C code based on the Assembly code given. It may help to first fill out the mappings of the registers/addresses to the C variables

.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
#include int 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); }

Q1. Map the assembly address/register to the variables

-20(%rbp)

-16(%rbp)

-12(%rbp)

-8(%rbp)

-4(%rbp)

Q2. From the C code skeleton and answer what C could/should go in the blanks

(a)

(b)

(c)

(d)

(e)

(f)

(g)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!