← all animations

LITTLE MAN COMPUTER

Write assembly, assemble it into numeric mailboxes, and run it through the fetch-decode-execute cycle one instruction at a time.

PROGRAM
Click Assemble to load the program.
ACC
0
PC
0
INSTRUCTION
–

How the Little Man Computer works — step by step

What the LMC is

The Little Man Computer is a tiny model of a real CPU, designed for teaching. Imagine a single person (the “little man”) sitting in a room with 100 numbered mailboxes, a small calculator (the accumulator), a finger pointing at the next mailbox to read (the program counter), an in-tray (input), and an out-tray (output). That’s the whole machine.

The pieces (on the right of the page)

Instructions are just numbers

Every LMC instruction is a 3-digit number. The first digit is the opcode (what to do); the last two digits are the operand (which mailbox to use).

Example: ADD 5 becomes the number 105 — opcode 1 (ADD), operand 05. The Assemble button does this conversion: it reads your assembly text and fills the mailboxes with the right numbers.

The Fetch–Decode–Execute cycle

Every instruction goes through the same three steps. Click Step once and you'll run one full cycle:

  1. Fetch — copy the number in mailbox[PC] into the INSTRUCTION register, then add 1 to PC so it points at the next instruction.
  2. Decode — split the 3 digits into opcode and operand to work out what to do.
  3. Execute — do it.
    • LDA addr → ACC = mailbox[addr] (the cyan-flash on the memory grid shows which mailbox was touched).
    • STA addr → mailbox[addr] = ACC.
    • ADD addr → ACC = ACC + mailbox[addr].
    • SUB addr → ACC = ACC − mailbox[addr].
    • BRA addr → jump: PC = addr.
    • BRZ addr → jump only if ACC is zero.
    • BRP addr → jump only if ACC is positive (≥ 0).
    • INP → take the next number from the Inputs box, put it in ACC.
    • OUT → copy ACC into the OUTPUT list.
    • HLT → stop.

Then the cycle repeats with the new PC. The machine keeps running until it hits a HLT.

The instruction set in one table

MnemonicCodeWhat it does
INP901take the next input into ACC
OUT902send ACC to OUTPUT
LDA xx5xxload mailbox[xx] into ACC
STA xx3xxstore ACC into mailbox[xx]
ADD xx1xxACC = ACC + mailbox[xx]
SUB xx2xxACC = ACC − mailbox[xx]
BRA xx6xxunconditional jump to xx
BRZ xx7xxjump to xx if ACC = 0
BRP xx8xxjump to xx if ACC ≥ 0
HLT000stop
DAT nnnndeclare a data slot (optional initial value)

Labels

Labels are nicknames you give to a mailbox address. When the assembler sees loop  LDA n, it remembers “the address of that instruction is called loop” — so any later BRA loop is automatically turned into the correct mailbox number. Labels save you from having to count addresses by hand.

Three patterns of control flow

Every program — in any language — is built from three patterns. LMC shows them in their rawest form:

Walking through one cycle — “ADD 1” in mailbox 3

Suppose the PC is 3, mailbox[3] holds 101 (ADD 1), mailbox[1] holds 7, and ACC is 5.

  1. Fetch: read mailbox[3] → 101. INSTRUCTION = ADD 1. PC becomes 4.
  2. Decode: 1xx means ADD; operand is 01.
  3. Execute: read mailbox[1] → 7. ACC = 5 + 7 = 12.

Then the cycle starts again with PC = 4. Press Step on the simulator and watch the orange PC arrow move, the ACC change, and the mailbox you read flash cyan.

How to use this page

  1. Pick an example from the dropdown above the code editor.
  2. Click ⚙ Assemble — the mailboxes fill with numbers.
  3. Click ⏭ Step to advance one instruction at a time and read every change, or ▶ Run to play through and adjust the Speed slider to taste.
  4. Change the Inputs and assemble again to see the same program behave with different data.
  5. Edit the code yourself — the simulator will tell you about any assembly errors.