In this project, you will complete two utility functions that will be useful for processing the input for a disassembler (in phase 2). You will also complete a test driver to test your two functions. (A test driver is the main function written to "drive" tests of other functions.)
Get started:
The goal of the project is to gain more familiarity with C by writing some useful functions for a future programming project.
Download the code in zip file.
Files description:
disUtilDriver.c |
Test driver, with main function |
verifyMIPSInstruction.c |
Utility function 1, used to verify the input format |
binToDec.c |
Utility function 2, convert input bin to dec |
Makefile |
indicates how to compile both this program and the future disassembler program |
testfileStarter.txt |
A simple input test file |
same.h |
A header file |
process_arguments.c/.h |
processes command-line arguments passed to the main function; used in test driver |
printFuncs.h |
A header file for the following two print functions |
printDebug.c |
Prints debugging messages, used in test driver |
printError.c |
Prints error messages, used in verifyMIPSInstruction |
Disassembler.h |
Will be used in phase 2 |
getRegName.c |
Will be used in phase 2 |
The Makefile contains information for the make command, telling it how to compile this program (and the future disassembler program). Check the contents of Makefile to understand its structure. To compile this program, type make disUtil at a command-line prompt.
The make command will create a compiled executable called disUtil. You can run your program by typing its name at the command line. It takes two optional parameters: a filename and an integer 1 if you want to turn on debugging. If you run the program with the minimalist starter test file provided above, you'll see that for now it just prints the contents of the test file with a line number inserted at the beginning of each line.
./disUtil testfileStarter.txt ./disUtil testfileStarter.txt 1 |
Compare the test file with your output and then modify the test file and run the program again to verify its behavior. Test the program with and without the second parameter, 1.
Project description
The input file for the disassembler we will write shortly will contain strings representing MIPS instructions, one per line. Actual MIPS instructions would be stored in 32-bit integers; instead, our file will contain lines of 32 characters ('0' or '1'), where each line represents the 32 bits in a machine language MIPS instruction.
The purpose of the functions you are completing in this project is to read in the strings representing MIPS instructions, make sure they are valid, and decode subsets of the instructions in decimal format.
verifyMIPSInstruction:
The main function in the test driver (disUtilDriver.c) currently reads lines in from a file until reaching the end of the file. If the line ends with a newline, the program strips the newline from the string by replacing it with a null byte. The code that is missing should call verifyMIPSInstruction to verify that the format contains a MIPS instruction in the proper format or print an error if it does not. If the instruction is valid, main should call binToDec several times, with various parameters, to test it effectively and print the results. (Until you have completed the missing code in binToDec, a single call will be a sufficient test.)
The verifyMIPSInstruction function should verify that the string provided to it is 32 characters long and that the characters in the string are all 0's or 1's (character '0' or character '1'). If the instruction is valid, verifyMIPSInstruction should return 1. Otherwise, it should print an error message indicating the error and the line on which it occurred before returning 0.
Test your modifications before going further by adding appropriate data to the existing test file or by creating new data files. Be sure to include tests cases that exercise every path through your code as well as all appropriate boundary conditions (e.g., empty lines, too-long lines, invalid data in the first / last positions, etc.).
binToDec:
The binToDec function should interpret a substring of characters in an array as a binary number, convert it to an integer in decimal format, and return the integer. The first parameter is the array of characters; the second and third parameters are the beginning index and ending index of the substring. For example, assume A is a character array that contains the following characters.
1 0 1 1 0 1 0 0 1
The call binToDec(A, 2, 5) should convert the string of binary digits '1' '1' '0' '1' (the substring A[2] - A[5], inclusive) to the decimal integer 13 and return it. One efficient solution involves building the decimal number from the least significant digit to the most significant digit by adding in (or not) the appropriate power of two. Rather than calculating the power of two for each digit, you can store the power of two in a variable and multiply it by two when you go to the next digit. (What should the power-of-two variable be initialized to for the least significant digit?)
To test binToDec thoroughly, you should call it in a number of different ways whenever the instruction format is valid. Think particularly about what kinds of boundary conditions you should test for.
Makefile:
The Makefile I have provided specifies a set of compiler options that will help you catch many errors at compile time. These options generate warnings about questionable constructions that often indicate programmer confusion or actual logic errors. You may have to make adjustments to the Makefile, though, if the specific options or option names for your compiler are somewhat different.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of