Problem 3.60 in BO but using this assembly code instead: Besi, Becx $1, fedx $0, 5 .L3: testa je L5 VOKA anda gdi, 18 org 18, Brak sela Scl, rdx JUR .L3 .L5: ret.L5: ret Your solution should be an implementation of C function loop(). You can check your solution as you did for problem 1. Note that there is a mistake in the book in line 1 of page 313. The function signature should be long leep(long x, int n). The preceding code was generated by compiling C code that had the following overall form: long loop (long x, long n) long result - long maski for (mask- maak ;mask- " return result; result Your task is to fill in the missing parts of the C code to get a program equivalent to the generated assembly code. Recall that the result of the function is returned in register trax. You will find it helpful to examine the assembly code before, during, and after the loop to form a consistent mapping between the registers and the program variables. A. Which registers hold program values x, n, result, and mask? B. What are the initial values of result and mask? C. What is the test condition for mask? D. How does mask get updated? E. How does result get updated? Problems: 1. For a function with prototype long decode2(long x, long y, long z gcc generates the following assembly code: decode2: mox %rdi, %гax suba %rdx, %rax move %rax, %rdx imula %rax, %rdi sala $63,%rdx sarg $63, %rdx xora %rdx, %rdi leaq (%rdi,%rsi), %rax ret Parameters x, y, and z are passed in registers %rdi, %rsi, and %rdx. The code stores the return value in register %rax Reverse-engineer decode2. (In other words, write C code for decode2 that will have an effect equivalent to the assembly code shown.)
Problem 3.60 in BO but using this assembly code instead: Besi, Becx $1, fedx $0, 5 .L3: testa je L5 VOKA anda gdi, 18 org 18, Brak sela Scl, rdx JUR .L3 .L5: ret.L5: ret Your solution should be an implementation of C function loop(). You can check your solution as you did for problem 1. Note that there is a mistake in the book in line 1 of page 313. The function signature should be long leep(long x, int n). The preceding code was generated by compiling C code that had the following overall form: long loop (long x, long n) long result - long maski for (mask- maak ;mask- " return result; result Your task is to fill in the missing parts of the C code to get a program equivalent to the generated assembly code. Recall that the result of the function is returned in register trax. You will find it helpful to examine the assembly code before, during, and after the loop to form a consistent mapping between the registers and the program variables. A. Which registers hold program values x, n, result, and mask? B. What are the initial values of result and mask? C. What is the test condition for mask? D. How does mask get updated? E. How does result get updated? Problems: 1. For a function with prototype long decode2(long x, long y, long z gcc generates the following assembly code: decode2: mox %rdi, %гax suba %rdx, %rax move %rax, %rdx imula %rax, %rdi sala $63,%rdx sarg $63, %rdx xora %rdx, %rdi leaq (%rdi,%rsi), %rax ret Parameters x, y, and z are passed in registers %rdi, %rsi, and %rdx. The code stores the return value in register %rax Reverse-engineer decode2. (In other words, write C code for decode2 that will have an effect equivalent to the assembly code shown.)
Related questions
Question
![Problem 3.60 in BO but using this assembly code instead:
Besi, Becx
$1, fedx
$0, 5
.L3:
testa
je
L5
VOKA
anda
gdi, 18
org
18, Brak
sela
Scl, rdx
JUR
.L3
.L5:
ret.L5:
ret
Your solution should be an implementation of C function loop(). You can check your solution as
you did for problem 1. Note that there is a mistake in the book in line 1 of page 313. The function
signature should be long leep(long x, int n).
The preceding code was generated by compiling C code that
had the following overall form:
long loop (long x, long n)
long result -
long maski
for (mask-
maak
;mask-
"
return result;
result
Your task is to fill in the missing parts of the C code to get a
program equivalent to the generated assembly code. Recall
that the result of the function is returned in register trax. You
will find it helpful to examine the assembly code before, during,
and after the loop to form a consistent mapping between the
registers and the program variables.
A. Which registers hold program values x, n, result, and
mask?
B. What are the initial values of result and mask?
C. What is the test condition for mask?
D. How does mask get updated?
E. How does result get updated?](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3b25bdcc-1f5e-4716-88d3-d1e15ee2df25%2Fb09231dd-6ebb-4058-8b2a-e1f603bf8928%2Fnda177g_processed.png&w=3840&q=75)
Transcribed Image Text:Problem 3.60 in BO but using this assembly code instead:
Besi, Becx
$1, fedx
$0, 5
.L3:
testa
je
L5
VOKA
anda
gdi, 18
org
18, Brak
sela
Scl, rdx
JUR
.L3
.L5:
ret.L5:
ret
Your solution should be an implementation of C function loop(). You can check your solution as
you did for problem 1. Note that there is a mistake in the book in line 1 of page 313. The function
signature should be long leep(long x, int n).
The preceding code was generated by compiling C code that
had the following overall form:
long loop (long x, long n)
long result -
long maski
for (mask-
maak
;mask-
"
return result;
result
Your task is to fill in the missing parts of the C code to get a
program equivalent to the generated assembly code. Recall
that the result of the function is returned in register trax. You
will find it helpful to examine the assembly code before, during,
and after the loop to form a consistent mapping between the
registers and the program variables.
A. Which registers hold program values x, n, result, and
mask?
B. What are the initial values of result and mask?
C. What is the test condition for mask?
D. How does mask get updated?
E. How does result get updated?
![Problems:
1. For a function with prototype
long decode2(long x, long y, long z
gcc generates the following assembly code:
decode2:
mox %rdi, %гax
suba %rdx, %rax
move %rax, %rdx
imula %rax, %rdi
sala $63,%rdx
sarg $63, %rdx
xora %rdx, %rdi
leaq (%rdi,%rsi), %rax
ret
Parameters x, y, and z are passed in registers %rdi, %rsi, and %rdx. The code stores
the return value in register %rax
Reverse-engineer decode2. (In other words, write C code for decode2 that will
have an effect equivalent to the assembly code shown.)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3b25bdcc-1f5e-4716-88d3-d1e15ee2df25%2Fb09231dd-6ebb-4058-8b2a-e1f603bf8928%2Fe1pd5f_processed.png&w=3840&q=75)
Transcribed Image Text:Problems:
1. For a function with prototype
long decode2(long x, long y, long z
gcc generates the following assembly code:
decode2:
mox %rdi, %гax
suba %rdx, %rax
move %rax, %rdx
imula %rax, %rdi
sala $63,%rdx
sarg $63, %rdx
xora %rdx, %rdi
leaq (%rdi,%rsi), %rax
ret
Parameters x, y, and z are passed in registers %rdi, %rsi, and %rdx. The code stores
the return value in register %rax
Reverse-engineer decode2. (In other words, write C code for decode2 that will
have an effect equivalent to the assembly code shown.)
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)