The purpose of this assignment is to introduce you to systems programming in C, which is the language that we will be using throughout the semester. You must complete this program in ANSI C, not C99, C++ or C#. Your program must compile and run on your virtual machine, although you may develop it on any machine you like, such as on the MultiLab.
You will be graded on exact adherence to these specifications.
prog1.c, and the executable program must be called
prog1 file.datawhere file.data can be any valid Unix file name.
intis 4 bytes. The elements of the array are numbered starting at 0.
prog1), one command per input line. All values that your program prints should be directed to standard output (which could be the screen or a file, again depending on how you invoke
prog1), in hexadecimal (8 characters, lower case), one result per line, unless indicated otherwise. The following list shows the valid commands and their meaning. Here, n and m are non-negative base-10 integers representing indices into your array of chunks, and b represents a non-negative base-10 integer representing a shift amount. Each command ends with a newline (\n).
|print element n in decimal (suppress leading zeros)|
|print element n in hex|
|print element n in octal (suppress leading zeros)|
|print the lowest order (first) byte of element n in 2 hex characters|
|print the second byte of element n in 2 hex characters.|
|print the third byte of element n in 2 hex characters.|
|print the fourth byte of element n in 2 hex characters.|
|print the low 16 bits of element n in 4 hex characters.|
|print the high 16 bits of element n in 4 hex characters.|
|print the sum of elements n and m, ignoring overflow|
|print the product of elements n and m, ignoring overflow|
|print the bitwise and of elements n and m|
|print the bitwise or of elements n and m|
|print the bitwise xor of elements n and m|
|print the result of right-shifting element n by b bits|
|print the result of left-shifting element n by b bits|
|quit with status 0; do not print anything|
|) and parameters.
Makefilemust be able to compile your program when you run
make prog1You should start with the
Makefilethat you can get this way:
wget http://www.cs.uky.edu/~raphael/courses/CS270/project1/MakefileYou may modify this file.
gcc -Wall -g prog1.c -o prog1The
Makefilewe provide invokes the compiler exactly this way.
You can get a sample data file, a working executable, and a program that creates data:
wget http://www.cs.uky.edu/~raphael/courses/CS270/project1/testData wget http://www.cs.uky.edu/~raphael/courses/CS270/project1/workingProgram wget http://www.cs.uky.edu/~raphael/courses/CS270/project1/createData.pl chmod +x workingProgram createData.pl
You might want to use the od ("octal dump") program to inspect the test data:
od -t d4 -t x4 testData
The man program can tell you about useful programs and functions in the C
library. For example, run this program to find out about the
man 3 strtokThe
3means "section 3 of the manual", which is where the C library is documented. You can leave off the "3" and find all references to
strtok(). You might find the following functions useful:
open fopen read fread close fclose printf fprintf scanf fscanf sscanf strtok strspn fgets atoi
For programs, correctness is an important criterion, but is by no means the whole story. Here are some suggestions for programming in general.
Makefileand partially in
http://www.cs.uky.edu/~raphael/writing.htmlfor guidance. Run all code and documentation through a spelling checker such as ispell or aspell.
http://www.cs.uky.edu/~raphael/checklist.htmlfor suggestions on programming standards, and
http://www.cs.uky.edu/~raphael/programming.htmlfor techniques specific to C and basic information about Unix.
Makefile, and a
file. Do not
submit other files. To create your submission, tar and compress all files that
you are submitting. There is a recipe in the
Makefile that we provide:
README file must be a text file, not a file in MS Word,
PostScript, PDF, or any other non-text format.
README should include at least your name, a list of the files
you are submitting, a short description of the project, any known bugs, and a
short description of your testing.
Upload your submittal via
You may upload it as many times as you like; we grade only the last submission.
Once we have graded a submission, we ignore later submissions.