2000s · Yale Patt and Sanjay Patel
LC-3
The LC-3, short for Little Computer 3, is the machine thousands of students meet in their first computer systems course. It is small enough to learn in a week, but complete enough to run real programs with subroutines, I/O and an operating system’s worth of service routines.
| Designed by | Yale N. Patt and Sanjay J. Patel |
|---|---|
| Book | Introduction to Computing Systems: From Bits and Gates to C and Beyond |
| Introduced | With the book’s second edition (early 2000s), succeeding the LC-2 |
| Word size | 16 bits; memory is word-addressed |
| Address space | 65,536 words (x0000 to xFFFF) |
| Registers | R0 to R7, PC, IR, condition codes N, Z, P |
| Opcodes | 15 (4-bit opcode field; one value reserved) |
| I/O | Memory-mapped keyboard and display registers |
Why it was built
Yale Patt and Sanjay Patel believe students should learn computing from the bottom up: transistors, then gates, then a real machine, then assembly, then C. Most real processors are too big and too messy for a first course, so they designed their own. The LC-3 keeps the parts that teach something and drops the rest. Their textbook builds up to it chapter by chapter, and many universities use it in introductory courses.
How it works
Everything is 16 bits: the words, the addresses and the instructions. Memory holds 65,536 words, and programs usually start at address x3000 (LC-3 writes hex with a leading x). There are eight general-purpose registers, R0 to R7. After any instruction that writes a register, three condition codes record whether the result was Negative, Zero or Positive, and conditional branches test them.
Each instruction uses its top four bits as the opcode. That leaves 12 bits for operands, which is tight, so many instructions use a short signed offset from the program counter rather than a full address.
| Group | Instructions |
|---|---|
| Operate | ADD, AND, NOT |
| Data movement | LD, LDI, LDR, LEA, ST, STI, STR |
| Control | BR (with any mix of n, z, p), JMP/RET, JSR/JSRR, TRAP, RTI |
The operate group is famously minimal: add, AND and NOT. There is no subtract and no OR. To compute a − b you flip b with NOT, add 1, then add, which is two’s complement in action. OR comes from NOT and AND, using De Morgan’s law. Students learn quickly that a few well-chosen operations go a long way (see logic gates and truth tables).
The data movement instructions show off addressing modes: PC-relative (LD, ST), indirect through a pointer in memory (LDI, STI), base plus offset (LDR, STR), and LEA, which computes an address without touching memory.
TRAPs and I/O
Input and output use memory-mapped device registers: the keyboard status and data registers at xFE00 and xFE02, the display status and data registers at xFE04 and xFE06. Programs usually do not poke them directly, though. They call system service routines with TRAP:
| Trap | Name | What it does |
|---|---|---|
x20 | GETC | Read one character into R0 |
x21 | OUT | Print the character in R0 |
x22 | PUTS | Print the string R0 points to |
x23 | IN | Prompt, then read and echo a character |
x25 | HALT | Stop the machine |
That gives students a first taste of an operating system: code they did not write, reached through a table, running on their behalf.
Why it matters
The LC-3 is a common first assembly language for computer engineering students, and the book continues past it to show how C maps onto the same machine: the stack, local variables, function calls. A third edition extends the story to C++. Free simulators make it easy to try at home.
The LC-3 in NANDSIM
The museum LC-3 is rebuilt from NAND gates and runs real LC-3 programs. Open it up to inspect R0 to R7, the condition codes and memory as each instruction executes.