CS 213, Fall 2000Homework Assignment H1, Part AAssigned: Sept. 12, Due: Mon., Sept. 18, 11:59PMRandy Bryant ([email protected]) is the lead person for this assignment.The purpose of this assignment is to learn IA32/Linux assembly language and to become familiar with howC code is translated into assembly. You will do this by looking at a series of assembly language functionsand decompiling them to find the C source code that produced them. Reverse engineering this code willimprove your understanding of both the C constructs and the assembly code.IntroductionIn this assignment you will be given the assembly code file for a set of functions. Your task is to derive Csource code that compiles into code that is functionally equivalent. In fact, you should strive to make yourcode produce assembly code that is identical to the supplied assembly code. None of the functions requiresmore than a few lines of code.When you are trying to figure out what a given functions does, try creating a small example to see whatcode the compiler emits. If you can create a series of small functions that produce part of the answer, youcan then piece them together to create a solution.LogisticsYou must work alone on this assignment. The only “hand-in” will be electronic. Any clarifications andrevisions to the assignment will be posted on Web page assigns.html in the class WWW directory.All files for this assignment are in the directory:/afs/cs.cmu.edu/academic/class/15213-f00/H1aYou will want to do your work on one of the class “fish” machines to be sure that you are using the correctversion of the GCC compiler. See the class WWW pages for more information on these machines.First create a (protected) directory to work in, and copy our template code using the command:tar -xvf /afs/cs.cmu.edu/academic/class/15213-f00/H1a/H1a.tar1This will create a variety of files, including one named probs.c. In this assignment you will only modifythis file.Your first step should be to fill in your name and Andrew ID in the structure at the beginning of this file.Your task is to fill in the bodies of six functions in probs.c, named arith, mem, optarith, ifcode,whilecode, and forcode, respectively. Your goal is to make them have the same functionality as thecorresponding functions in the file probs-solve.s.The original C code for these functions has the following characteristics:arith: Some simple arithmetic operations.mem: Some memory referencing through pointers.optarith: Some arithmetic operations that get optimized by the compiler.ifcode: A conditional expression.whilecode: A while loop.forcode: A for loop.Although you could brute force your solution by writing C code that uses goto’s and things like that, try towrite the cleanest and most abstract C code you can.EvaluationYou will onlyget credit for problems in which you are able to exactly match the functionality of the assemblycode versions. The six problems count one point apiece. Use the command make atest to generate aprogram that will run your functions against the original functions on some test data. See the file READMEfor documentation on this program.Hand InHand in your solution using the commandmake handin NAME=yourname VERSION=XXwhere yourname is your Andrew ID, and XX is the version number, i.e., 2, 3, .... Only your highestnumbered version submitted before the deadline will be
View Full Document