Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following assembly code: .file hwk5_3.c .text .globl main .type main, @function main: endbr64 pushq %rbp movq %rsp, %rbp movl $539107842, -8(%rbp) movl $-1,

Consider the following assembly code:

 .file "hwk5_3.c" .text .globl main .type main, @function main: endbr64 pushq %rbp movq %rsp, %rbp movl $539107842, -8(%rbp) movl $-1, -4(%rbp) movl -8(%rbp), %eax cltd shrl $28, %edx addl %edx, %eax andl $15, %eax subl %edx, %eax movl %eax, %edx movl -8(%rbp), %eax shrl $28, %eax cmpl %eax, %edx jne .L2 sarl $4, -8(%rbp) movl -8(%rbp), %eax cltd shrl $28, %edx addl %edx, %eax andl $15, %eax subl %edx, %eax movl %eax, %edx movl -8(%rbp), %eax sarl $20, %eax andl $15, %eax cmpl %eax, %edx jne .L3 sarl $4, -8(%rbp) movl -8(%rbp), %eax cltd shrl $28, %edx addl %edx, %eax andl $15, %eax subl %edx, %eax movl %eax, %edx movl -8(%rbp), %eax sarl $12, %eax andl $15, %eax cmpl %eax, %edx jne .L4 sarl $4, -8(%rbp) movl -8(%rbp), %eax cltd shrl $28, %edx addl %edx, %eax andl $15, %eax subl %edx, %eax movl %eax, %edx movl -8(%rbp), %eax sarl $4, %eax andl $15, %eax cmpl %eax, %edx jne .L5 movl $8, -4(%rbp) jmp .L6 .L5: movl $6, -4(%rbp) jmp .L6 .L4: movl $4, -4(%rbp) jmp .L6 .L3: movl $2, -4(%rbp) jmp .L6 .L2: movl $0, -4(%rbp) .L6: movl $0, %eax popq %rbp ret

This code came from skeleton C file below after running the folloing command: gcc -O0 -fno-asynchronous-unwind-tables -S hwk5_3.c Complete the blanks in the C code given below using the provided assembly code.

#include  int main() { int num = _____(a)_____; int result = -1; if ((num % ____(b)_____) _____(c)_____ ( _____(d)_____)) { num = num >> 4; if ((num % _____(e)_____) _____(f)_____ ( _____(g)_____)) { num = num >> 4; if ((_____(h)_____) _____(i)_____ ( _____(j)_____)) { num = num >> 4; if ((_____(k)_____) _____(l)_____ (_____(m)_____)) { result = 8; } else { result = 6; } } else { result = 4; } } else { result = 2; } } else { result = 0; } return 0; }

The cltd instruction fills the edx register with the most significant bit of the eax register. In practice this is a sneaky way to zero out edx when the compiler knows the value in eax is positive.

1.

Fill in the blank for (a).

2.

Fill in the blank for (b).

3.

Fill in the blank for (c)

4.

Fill in the blank for (d)

5.

Fill in the blank for (e)

6.

Fill in the blank for (f)

7.

Fill in the blank for (g)

8.

Fill in the blank for (h)

9.

Fill in the blank for (i)

10.

Fill in the blank for (j)

11.

Fill in the blank for (k)

12.

Fill in the blank for (l)

13.

Fill in the blank for (m)

14. For the value of num provided, what will be the value in result after the code executes (but before the program ends)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

a. How are members selected to join the team?

Answered: 1 week ago

Question

b. Will new members be welcomed?

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago