Problem 1. Each of the following assembly code snippets corresponds to the body of a C function consisting of a single control structure: a loop, if statement, or case switch. (Compiler directives, like cfi_startproc, and instructions that do not affect the semantics, like endbr64, have been removed for readability. And yes, of course the functions are all named foo.) For each one, write C code that would compile to similar assembly for the body. In other words, figure out what the code is doing and write C code to do that. You will have to figure out how many variables are being computed with, and make up names for them. (The code was compiled with -Og.)
Problem 1. Each of the following assembly code snippets corresponds to the body of a C function consisting of a single control structure: a loop, if statement, or case switch. (Compiler directives, like cfi_startproc, and instructions that do not affect the semantics, like endbr64, have been removed for readability. And yes, of course the functions are all named foo.) For each one, write C code that would compile to similar assembly for the body. In other words, figure out what the code is doing and write C code to do that. You will have to figure out how many variables are being computed with, and make up names for them. (The code was compiled with -Og.)
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:Problem 1. Each of the following assembly code snippets corresponds to the body of a C function
consisting of a single control structure: a loop, if statement, or case switch. (Compiler directives,
like cfi_startproc, and instructions that do not affect the semantics, like endbr64, have been
removed for readability. And yes, of course the functions are all named foo.) For each one, write
C code that would compile to similar assembly for the body. In other words, figure out what the
code is doing and write C code to do that. You will have to figure out how many variables are being
computed with, and make up names for them. (The code was compiled with -0g.)
foo:
a.
b.
C.
.L3:
.L2:
foo:
.L2:
foo:
.L3:
.L2:
movl $0, %edx
movl $0, %eax
jmp .L2
addl
(%rdi), %edx
addl
$1, %eax
leaq 4(%rdi), %rdi
cmp1 %esi, %eax
jl
.L3
movl
%edx, %eax
ret
movl (%rdi), %eax
cmpl $10, %eax
jle .L2
subl $10, %eax
movl %eax, (%rdi)
ret
leal 1(%rax,%rax, 2), %eax
movl %eax, (%rdi)
ret
movl $0, %eax
jmp .L2
addl $1, %eax
cmpb $0, (%rdi)
jne .L3
ret

Transcribed Image Text:d. (Note: this one has nested control structures. Hint: one is a conditional.)
foo:
.L3:
.L2:
.L5:
movl $0, %ecx
movl $0, %eax
jmp .L2
sarl %edi
sarl %esi
addl $1, %eax
cmp1 $31, %eax
jg .L5
movl %edi, %edx
xorl %esi, %edx
testb $1, %d1
jne
.L3
addl $1, %ecx
jmp
.L3
movl %ecx, %eax
ret
3
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education