Homework 1: Numerical Representations and Disassembly of Object Files
Assigned |
Monday, January 13 |
Due Date |
Friday, January 24 at 5:00 PM |
Submissions |
Submit a PDF file of your solutions here |
Introduction
The purpose of written homework assignments is to get you thinking
about the topics being covered in lecture and in readings in the
textbook which are not represented in the hands-on, programming lab
assignments. These written assignments also better prepare you for
course examinations. It is worth noting that the book contains many
practice problems similar to the problems we ask on these written
assignments. The solutions for those practice problems are located at
the end of each chapter and should give you a feel for the kind of
answers we expect you to turn in for these kind of assignments.
Logistics
Please write up your answers and submit them as a PDF file in the online
dropbox. This simplifies our grading and ensures we read your answers clearly.
If you don't know how to create a PDF, a quick internet search should help, or
ask us.
We will provide solutions to all of the problems in the written homework
assignments in a timely fashion after the assignment is due. This may be around
4 or 5 days after the due date, in general, because a student may use up to 3 late days on an assignment.
Questions
Answer the following problems from the textbook. If a practice problem is
listed, try to solve the problem on your own first, then check your answer at
the end of the chapter. Make sure you understand the solution provided, then
complete the additional questions below. Your write-up only needs to contain the
information necessary to understand your answer to the additional questions -
you do NOT need to turn in the answer to the practice problem in its
entirety.
- Suppose we are given the task of generating code to multiply integer variable x by various different constant factors K. To be efficient, we want to use only the operations +, -, and <<. For the following values of K, write C expressions to perform the multiplication using at most three operations per expression. K = 17, K = -7, and K = 60.
- Homework Problem 2.81 (pp. 126-127), parts A, D, and E.
(Clarification: By "describe the underlying mathematical
principles" when the given property always holds, we do not mean you need a
formal proof, just an informal description of why it works.)
- Recall that a floating point number is of the form: (-1)S x M x
2E. M is the mantissa and 2E is the exponent. Also recall
that M ranges from 1.0 to (almost) 2.0. Tell us the values of M and E for the
number 11.25. You do not need to encode this in IEEE 754
representation. Please just tell us the decimal values of M and E, and the
binary value of the
frac
. (Recall frac
= M - 1.0.)
- Homework Problem 3.54 (pp. 294-295).
- For this problem you will use the jack-of-all-trades tool objdump
to examine executable programs on Linux. Be sure to work on this problem
on attu or the CSE home VM. You will need a copy of the code that you
turned in for Lab 1 (your code does not have to be entirely correct or
complete, but at least some of your puzzle functions should be filled in).
- Run make in your Lab 1 directory to build your code. Run the
command objdump -t btest | grep text and examine the output.
What do the strings in the rightmost column of the output represent?
- Use objdump to disassemble your btest code (review the lecture
slides or check the man page to find the right flag). Find the
labels in the assembly code corresponding to your bit puzzle functions.
What x86 assembly instructions appear to perform right-shift and
left-shift operations?
- Most Linux distributions include several
other useful programs for examining binary files containing machine code.
Try out commands such as ldd, file, nm,
strings and
readelf, and try other flags with objdump. Report something
neat, unusual, or unexpected that you find. Don't forget to use the man
pages to learn more about all of these programs.
- Extra Credit (a little): run the objdump -t command on a
different program on the system - choose one in the /usr/bin/
directory. You will likely see the output "SYMBOL TABLE: no
symbols". Why does objdump -t appear to work on your program,
but not on others?
Notes
Make sure you are using the 2nd edition of Computer Systems: A
Programmer's Perspective. If you're not using the right book, you
might be doing the wrong problems!
Submitting Your Work
Please turn in a PDF file containing your answers to
the Catalyst
Drop Box for this assignment. We will not accept submissions
that are not in PDF format.