My Project
|
struct
) and how to initialize
structures at compile time.&
).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.
cd
to it.Save Target As..
for each
of the files:
make
../testUtil
. You will see a usage message which tells
you how to use the program.util_bin_search()
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.
util_is_valid_label()
util_is_valid_label()
. See the
documentation to determine what defines a valid label. Test it by
using the option label
in testUtil
.
util.c
using the
Checkin
tab under the PA9A assignment. Submit
only the util.c file.