My Project
cs270 Programming Assignment - Assembler Utilities
Programming Assignment PA9A: CS 270 Computer Organization

CS 270, Fall 2014
Programming Assignment PA9A
Assembler Utilities

PA9A due Thursday, Nov. 20 at 11:59pm, no late submissions.


Goals of Assignment

In this short assignment you will write two utility routines for the lc3 assembler. This assignment serves several purposes:

Overview

In writing large projects, it is convenient to build utility routines that support the completion of the larger project. These utilities are in separate files so that they may be written and thoroughly tested independently of the project as a whole. Also, by splitting up the work, it can be spread over a team of programmers working in parallel. This assignment is an example of a set of utility routines for the assembler.

One of the tasks required in the assembler is converting symbolic names that are used in an assembly language program to their underlying representation. For example the word "ADD" needs to be converted to the numeric code that the LC3 uses for the operation. Assemblers for other assembly lanuages will also have the name "ADD", but will likely have a different numeric code.

One way to convert words to values is to have a long sequence of statements like:


   if (strcmp(name, "ADD") == 0)
     code = OP_ADD;
   else if (strcmp(name, ".FILL") == 0)
     code = OP_FILL
   ...
An alternative this is to search a data structure. The advantage of this is twofold. First the search code is written once and reused multiple times. Secondly, the contents of the data structure can actually be read from a file, thus changing the behavior of the program without changing the program itself. This is exactly what happens in program like lex which take a textual description of a language and automatically produces a lexical analyzer for it. If you ever take a compiler course (e.g. cs453), you will learn to use these tools.

In this assignment there are three functions for converting names to values:

The fourth function analyzes a string and determines if it is a valid label.


Getting Started

  1. Create a directory for this assignment and cd to it.
  2. Copy the following files to the directory you created. It is easiest to right click on the link, and do a Save Target As.. for each of the files:
  3. Build the executable by typing make.
  4. You now have a functional program, but it will not produce the correct results.
  5. Enter ./testUtil. You will see a usage message which tells you how to use the program.
  6. You are now ready to begin implementation. You have two functions to implement. In addition, you must complete one of the data arrays.
  7. Implement functions one at a time and test as you go.

Implement util_bin_search()

This function is used three places in your code. Its purpose is to search a sorted array and to find a name. If that name is found, it returns a pointer to the structure containing that name. It is used is to lookup a name like ADD or .FILL and determine the opcode associated with that name. You have learned how to write binary search in your previous courses. Build on your knowledge and complete this implementation on C. To test your code, use the reg, ccode or op option in testUtil.

Implement util_is_valid_label()

Implement the function util_is_valid_label(). See the documentation to determine what defines a valid label. Test it by using the option label in testUtil.

Checking in Your Code

You will submit the single file util.c using the Checkin tab under the PA9A assignment. Submit only the util.c file.