The UNIX operating system has a command named wc (word count). In its simplest form, wc reads characters from stdin until end-of-file, and prints to stdout a count of how many lines, words, and characters it has read. A word is a sequence of characters that is delimited by one or more whitespace characters.
Consider some examples. In the following, a space is shown as "s" and a newline character as "n".
If the file named proverb contains these characters:
Learningsissan treasureswhichn accompaniessitsn ownerseverywhere.n --sChinesesproverbn
then the command:
$ wc < proverb
prints this line to standard output:
5 12 82
If the file proverb2 contains these characters:
Learningsissan treasureswhichn accompaniessitsn ownerseverywhere.n --sssChinesesproverb
(note that the last "line" does not end with a newline character) then the command:
$ wc < proverb2
prints this line to standard output:
4 12 83
Another commonly used UNIX command is sort. In its simplest form, it reads lines from stdin, sorts them into ascending (i.e. alphabetical, i.e. lexicographic) order, and prints them to stdout. For example, if the file proverb contains these lines:
Learning is a treasure which accompanies its owner everywhere. -- Chinese proverb
then the command
$ sort < proverb
prints these lines to standard output:
-- Chinese proverb Learning is a accompanies its owner everywhere. treasure which
Note that the special character '-' has an ASCII code that is less than the ASCII codes of all alphabetic characters, and so the line that begins with '-' appears first. Also note that the uppercase characters have ASCII codes that are less than the ASCII codes of the lower case characters, and so the line that begins with 'L' appears before the line that begins with 'a'.
Your task is to translate given C versions of wc and sort into IA-32 assembly language, as specified below. Your assembly language programs should have exactly the same behavior (i.e. should write exactly the same characters to stdout) as the given C programs.
The file mywc.c in the /u/cos217/Assignment5 directory contains a C program that implements the subset of the wc command described above. Translate that program into assembly language, thus creating a file named mywc.s. It is acceptable to use global (i.e. bss section and data section resident) variables in mywc.s. But we encourage you to use local (i.e. stack resident) variables instead.
Your source code files should be such that you can build the mysort program using mysort.c along with either quicksort.c or quicksort.s, either partition.c or partition.s, and either swap.c or swap.s.
Design a testing strategy. Your testing strategy should include tests in three categories: (1) boundary condition testing, (2) logical path testing, and (3) stress testing.
Create text files to test your programs. Name each such file such that its suffix is ".txt". The command "ls *.txt" should display the names of all of your test text files, and nothing but your test text files.
Finally, create a UNIX shell script named grade5 to automate your testing strategy. A UNIX shell script is simply a text file that contains UNIX commands, and that has been made executable via the chmod command, for example, "chmod 700 grade5".
The grade5 script should build and execute your programs. The tests within the grade5 script should compare the output of programs built using the given C code vs. the output of programs built using your assembly language code. It should compare the output of at least these combinations:
It is acceptable for your grade5 script to call other scripts that you create. Each such script should have a name that is prefixed with "grade5". The command "ls grade5*" should display the names of all of your grading scripts, and nothing but your grading scripts.
Describe your testing strategy in your readme file. Specifically, for each of your .txt files, your readme file should contain the name of the file followed by up to six sections, in this format:
----------------------------------------------------------------------------------
filename.txtwc boundary condition tests:
Description of wc boundary condition test(s) implemented by this file, if anywc logical path tests:
Description of wc logical path test(s) implemented by this file, if anywc stress tests:
Description of wc stress test(s) implemented by this file, if anysort boundary condition tests:
Description of sort boundary condition test(s) implemented by this file, if anysort logical path tests:
Description of sort logical path test(s) implemented by this file, if anysort stress tests:
Description of sort stress test(s) implemented by this file, if any----------------------------------------------------------------------------------
You should not use a C compiler to produce your assembly language programs. Doing so would be considered an instance of academic dishonesty. Rather you should produce your assembly language programs manually.
We encourage you to develop "flattened" C code (as described in precepts) to bridge the gap between the given "normal" C code and your assembly language code. Using flattened C code as a bridge can eliminate logic errors from your assembly language code, leaving only the possibility of translation errors.
We also encourage you to use your flattened C code as comments in your assembly language code. Such comments can clarify your assembly language code substantially.
You should submit:
Your readme file should contain:
Submit your work electronically via the commands:
/u/cos217/bin/i686/submit 5 mywc.s quicksort.s partition.s swap.s /u/cos217/bin/i686/submit 5 readme grade5* *.txt
Comments in your assembly language programs are especially important. Each assembly language function (especially the main() function) should have a comment that describes what the function does. Local comments within your assembly language functions are equally important. Comments copied from corresponding "flattened" C code are particularly helpful.
Testing is a substantial aspect of the assignment. Approximately 20% of the grade will be based upon your testing strategy as described in your readme file, and as implemented by your testing scripts and text data files.
To encourage good coding practices, we will take off points based on warning messages during preparation of your programs.