CS202 - Assignment Six
Due: 2018-10-31 09:00a
Objectives
- Get some practice decompiling code
- Get more familiar with x86-64 by writing some simple functions
Warm-up [10 points]
Do Bryant problem 3.58
Some x86-64 assembly
For the most part, we don't have much call to actually write assembly -- it is generally more useful to be able to read it and figure out what it does. However, I would like you to get a taste for it, so we are going to write a couple of functions out by hand.
To help you out, I am providing you with a stub file that handles the setup and teardown for the assembly and a driver file that calls the functions from C. I am also giving you a header file. I've not talked about writing header files much in class, though we did briefly look at headers for some of the standard libraries. As we saw, they contain function prototypes -- just the definition of the functions including parameters and return types. These are used by the compiler to figure out how to use the function (what kind of parameters we are expecting to be pushed on the stack and what kind of return value we are expecting). This helps it generate the assembly and it also gives us a sanity check that we are calling the function the right way. We've not needed to write header files for own work, but they become necessary as soon as you have more than one file (as we will in this case).
The driver file is not actually one of your deliverables. It is an example of how you can use the assembly in a C program. You are welcome to write your own driver for testing (for example, one that just calls one of the following functions or has hard coded values inside). You could, for example, write individual C programs for each of the problems that test a variety of inputs for you.
Note: This assignment will particularly sensitive to versions of the compiler, etc. Your final submission must work on the lab machines.
(5 points)
avg(x,y)
- find the integer average of two numbers(10 points)
maxabs(x,y)
- return the number with the largest absolute value(10 points)
lookup(str, i)
-- return the character str[i]. Ifi
is out of bounds, return the null character.(10 points)
checksum(str)
-- xor all of the characters of the string together and return the number of 1s in the result. [5 points] As usual, there are five points for following all directions correctly.
Turning in your work
Submit the completed assignment on Canvas.