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

CodeMnemonicWhat it does
1xxADDAdd the contents of mailbox xx to the accumulator
2xxSUBSubtract the contents of mailbox xx from the accumulator
3xxSTAStore the accumulator into mailbox xx
5xxLDALoad mailbox xx into the accumulator
6xxBRABranch to mailbox xx, always
7xxBRZBranch to mailbox xx if the accumulator is zero
8xxBRPBranch to mailbox xx if the accumulator is zero or positive
901INPTake the next number from the input queue into the accumulator
902OUTCopy the accumulator to the output
000HLTStop
DATNot 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.