CS 47 - T. Howell - Spring, 2008
Homework Assignment #4
Due Thursday,
April 10, 2008 as an email attachment or on paper as described below.
You are to do six Practice Problems from the textbook. The solutions to these problems are
given at the back of each chapter. After solving each problem yourself and checking your
answer against the solution provided, you are modify the problem as described below and turn in
your solution to the modified problem.
Practice Problem 3.18
Change the array S from short to int, and change the index i from int to short.
Change the fourth expression from S[4*i+1] to S[2*i+3].
The result should be stored in register %eax if it is an int.
Practice Problem 3.19
Interchange the scale factors (4 and 8) in the leal instructions on lines 3 and 4 of the
assembly code. Insert the instruction sarl $1, %ebx between lines 7 and 8.
Practice Problem 4.1
Replace %ebx with %edi in the Y86 code (4 places).
Change the constant $15 to $31.
Insert the instruction xorl %eax, %eax after the rrmovl instruction and before the label loop:.
Change the addl instruction to subl.
Change the jmp instruction to jne.
Practice Problem 4.2
Replace the byte sequences as follows.
A. 0x100: 3080f8ffffff40720408000090
B. 0x200: a068800d02000070140200001030810c00000090
C. 0x300: 4054070000006202a00a10
D. 0x400: 6112760804000010
E. 0x500: 630ca008
Practice Problem 4.6
A. Identify the error in the solution on p. 368.
B. Write HCL for a 3-input parity circuit. Its inputs are a, b, and c. Its output
is 1 if an odd number of the inputs are 1. Otherwise the output is 0.
Practice Problem 4.8
Check csapp errata
for an error in the printed solution.
Write HCL for a circuit to find the second-largest of four word inputs A, B, C, and D.
That is, the output equals the word that is leftover when the largest input and the two
smallest inputs are removed. Assume that A, B, C, and D are known to be different, i.e.,
no two of them are equal. This will simplify your answer.
Submission
requirements and grading system
As noted above, you are to email me
your homework as a .doc or .rtf file hw4.doc ,
or hw4.rtf, which should contain
your solutions to the assigned problems.
This email must be sent to me by 23:59 on
Thursday, April 10 .
Your email must
have the following subject line:
CS 47 Section X Homework #4 John Doe
but of course with your own name and section number instead of
"John Doe and X." Please also
preserve all spacing and capitalization
in this subject line.
Since this homework assignment consists of written problems only, you may submit your homework
in paper form if you prefer. In this case it is due at the end of your class period on the due date.
Make sure your homework file contains the following information at the top of the first page: your
name, the class and section number, and the date.
I believe I have specified these problems very precisely above,
but if you have any questions about them
it is your responsibility
to ask me before the submission date.
Failure to observe
any of the submission requirements stated above may
result in a grade of 0 on this homework!