Little Man Computer
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 |
Instructions and data share the same memory
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.
One accumulator
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.