LC-3 Compiler

A C compiler is available from the "Patt and Patel" book website, and has been installed on the CS public Linux machines in the directory /p/bin/lcc. The compiler has some limitations including the lack of support for floating point, and inability to generate proper code for some complex integer expressions. But it should work fine for simple C programs. You can use the compiler as follows:

This command compiles your C program contained in filename.c and produces an object file named filename.obj, which can be loaded and run in the simulator.

As part of the compile process, the assembly language translation of the C program is produced first, and is available as filename.asm. The compiler then calls the LC-3 assembler on it to assemble and produce the final object file.

Notice that the assembler also produces the usual auxiliary files filename.hex and filename.dbg, that you might like to look at.

If the output file name is not specified by the -o option, then the output is written to a.asm, a.obj, a.hex and a.dbg.

A simple example C program is available here for you to test the compiler on. Save it as example.c and run the compiler on it, replacing "filename" with "example" in the above command. You might find it interesting to browse the assembly file example.asm produced by the compiler. Load example.obj in the lc3db simulator, and execute the program!

Last modified: 01/21/10 Don Fussell,