Little Man Computer
Write LMC assembly, assemble it into the mailboxes, then run it or step one instruction at a time while the program counter, accumulator and each mailbox update in front of you.
The Little Man Computer is a complete processor with one accumulator, one hundred mailboxes and eleven instructions. It is small enough to hold in your head and real enough that every idea in it transfers straight to a real CPU: the program counter, the accumulator, the fetch decode execute cycle and the difference between an instruction and the data it operates on.
Little Man Computer
Assemble and run LMC programs and watch the fetch decode execute cycle happen. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.
The instruction set
| Code | Mnemonic | What it does |
|---|---|---|
| 1xx | ADD | Add the contents of mailbox xx to the accumulator |
| 2xx | SUB | Subtract the contents of mailbox xx from the accumulator |
| 3xx | STA | Store the accumulator into mailbox xx |
| 5xx | LDA | Load mailbox xx into the accumulator |
| 6xx | BRA | Branch to mailbox xx, always |
| 7xx | BRZ | Branch to mailbox xx if the accumulator is zero |
| 8xx | BRP | Branch to mailbox xx if the accumulator is zero or positive |
| 901 | INP | Take the next number from the input queue into the accumulator |
| 902 | OUT | Copy the accumulator to the output |
| 000 | HLT | Stop |
| DAT | Not an instruction. Reserves a mailbox, optionally with a starting value |
The mailboxes hold both. That is the von Neumann idea, and it is why a program can accidentally treat its own instructions as data if a branch goes to the wrong place. Step through a program and watch the program counter to see it happen.
The LMC has exactly one general purpose register. Everything has to pass through it, which is why so many LMC programs are a run of load, do something, store. Real processors have dozens of registers precisely to avoid that traffic.