Thanks also to Dr Michelle Strout, Dr Sanjay Rajopadhye, and Dr Chris Wilcox for their many suggestions and hours of discussions.
Writing an LC3 simulator and/or assembler is a "larger" scale project that is appropriate for CS270. In the case of the simulator, the sophisticated Tcl GUI and gdb-like command line UI were preserved so that the student's simulator would include those features. Many assignments for CS270, including LC3 assembler and simulator, may be found here.
.a
files
contained in the distribution. The distribution was created for the use of
students so that they could install the tools on their personal computers.
A single compilation is required to complete the install. For a complete set of
source code, please contact me.
lc3CSU.XXX.tar
file. This will unpack into a directory named
lc3CSU
.
tar -xvpf lc3CSU.XXX.tar
cd
to the directory lc3CSU
Makefile
and make sure the variable GCC
is appropriate for your C compiler. Also, verify that sed
in in your $PATH
make
to build lc3sim
. It will also assemble the
file lc3os.asm
.$PATH
.
lc3os.asm
to provide GETS
.
This reads a string into the buffer given in R0
. The
assembler and simulator were updated appropriately.lc3os.asm
to provide NEWLN
.
This puts a newline character in R0
and uses OUT
.
The assembler and simulator were updated appropriately.RESERVED
opcode was used to provide PUSH/POP
as native instructions. More students correctly completed LC3 assembly
programs involving PUSH/POP
than when using the two
instruction sequence described in the book. Since the goal was for students
to learn how the stack is used in function calls, adding an instruction
seemed better than reverting to the approach of the book..ZERO DR
(shorthand for AND DR,DR,#0
)
, .COPY DR,SR1
(shorthand for ADD DR,SR1,#0)
and
.SETCC DR
(shorthand for ADD DR,DR,#0
)
were added to the assembler and simulator.-hex
was added to the assembler. This
results in a .hex
file instead of a .obj
file.
In the .hex
file, each value is four hex digits followed by
a newline. The simulator can load either format of file.-pass1
was added to the assembler.
When used, everything the assembler creates in pass one is printed. This
allows students to compare their assembler's work with the provided
version.-quiet
was added to the simulator. When
used, the welcome message is not printed and the registers are not printed
after a "step" in the simulator. To see the value of a register in the quiet
mode, the user does printreg regName
. The value of the single
named register (e.g. R1, PC, PSR
)is printed. In non-quiet mode,
printregs
operates as before. The switch is ignored if
lc3sim-tk
is in use.-norun
was added to the simulator. When
used, the simulator loads lc3os.obj
but does not attempt to
run it. This allows the student to incrementally develope the simulator,
one LC3 instruction at a time.BR
instruction with
nzp
of 0 is treated as an illegal instruction. The original
simulator treated this as a NOP
. The reasoning was that
nzp
of 0 can not be produced by any BR
instruction
processed by the assembler.Debug.c, Debug.h
- simple debugging macros wrapping
printf()
and provided in multiple assignmentshardware.c, hardware.h
- a model of the LC3 hardware.
In the original lc3sim.c
, the "hardware" was simply a set of
global variables accessed throughout the code. Here, the implementation is
hidden behind an interface.install.c, install.h
- specifies location of install.
This was handled by the configure
script of the original
code.lc3.c, lc3.h
- files describe LC3 ISA in a data
structure. Based on ideas/code found in the original files
lc3sim.h, lc3.f
. Factored out for use in both the assembler
and simulator.lc3sim.c
- gdb like controller of simulator. This is the
original lc3.c
file with a substantial amount of code
factored out into the other places. The code that provides the gdb like UI
and the connection to the Tcl-gui is largely intact.logic.c, logic.h
- the code that simulates the basic
fetch/decode/execute cycle of the LC3. This is what students complete
in the simulator project. This functionality was part of the origianl
lc3sim.c
.lc3sim-tk
- the Tcl GUI. Essentially unchanged from original.symbol.c, symbol.h
- symbol table. Based on
original code with a modified interface. Generaly completed as a stand alone
assignment and reused here and in the assembler.The files that make up the new LC3 assembler are listed below. Underlined files are completed by the students. All others are "read only".
assembler.c, assembler.h
- the main portion of
the assembler.debug.c, debug.h
- simple debugging macros wrapping
printf()
and provided in multiple assignmentslc3.c, lc3.h
- files describe LC3 ISA in a data
structure. Based on ideas/code found in the original files
lc3sim.h, lc3.f
. Factored out for use in both the assembler
and simulator.main.c
- the entry point of the assembler.symbol.c, symbol.h
- symbol table. Based on
original code with a modified interface. Generaly completed as a stand
alone assignment and reused here and in the simulator.tokens.c, tokens.h
- code to break a line of LC3 source
into an iterable set of tokens.util.c, util.h
- some simple utility
routines. Often a separate assignment reused in the assembler project.