SearchA-ZL › Little Man Computer

Little Man Computer

2026 Open source · Public domain Online

The Little Man Computer (LMC) is the classic teaching model of a stored-program computer, designed to be small enough to understand completely. This is an original implementation, written from scratch for emulators.org: 100 numbered mailboxes hold the program and its data, a single 3-digit accumulator does the arithmetic, and a program counter walks through the instructions. Programs are written in plain decimal, the hundreds digit is the opcode (ADD, SUB, STA, LDA, the branches, INP, OUT and HLT) and the last two digits are a mailbox address.

It boots with a demo already running: it reads a number from the input queue and counts it down to zero, printing each value. The whole machine - accumulator, program counter and every mailbox - is exposed to the shared debugger, so you can single-step the fetch-decode-execute cycle, set breakpoints on a mailbox, watch a mailbox for writes, and read the program back as a disassembly. An on-screen numeric keypad feeds the input queue on touch devices; the physical number keys work too.

Runs on: Web browser

Little Man Computer Online Emulator

Play Little Man Computer using JavaScript directly in your browser.

Configurations

ConfigurationEmulatorMachineOSLegal
Countdown demoLittle Man ComputeropenOpen ⛶

Chips

Notes

Embedding

The Little Man Computer here is authored from scratch in one small file, lmc.js. It is a plain global - LMC.create(canvas) returns a machine object whose whole state is ordinary JavaScript, so the debugger reaches straight into it with no wasm heap or hidden loop.

Boot. Create the machine on a <canvas>, load a program (a map of mailbox → value) and an initial INBOX, then run your own loop built on lmc.step() (execute exactly one instruction):

var lmc = LMC.create(canvas);
lmc.load({0:901, 1:399, 2:599, 3:902, 4:297, 5:399, 6:802, 7:0, 97:1}, [4]);
(function loop(){
  var r = lmc.step();               // 'ok' | 'halt' | 'input'
  lmc.render();
  if (r !== 'halt') requestAnimationFrame(loop);
})();

The machine is plain fields. Everything the debugger needs is live on the object:

MemberKindWhat it does
lmc.step()methodExecute exactly one instruction; returns 'ok', 'halt' or 'input' (blocked on an empty INBOX). The single-step primitive.
lmc.acc · lmc.pcfieldsThe 3-digit accumulator and the 2-digit program counter, read and written live.
lmc.memfieldThe 100 mailboxes (an array of 3-digit values).
lmc.peek(a) · lmc.poke(a,v)methodsSide-effect-free read / write of a mailbox, used by the debugger's memory views.
lmc.inbox · lmc.outboxfieldsThe input queue and output tape (arrays of numbers).
lmc.onWrite(a,v)hookCalled on every mailbox write; the boot uses it to implement watchpoints.

Because the accumulator, PC and mailboxes are ordinary JavaScript, breakpoints are a host-side Set of PC values checked before each step(), and watchpoints are checked inside onWrite - no changes to the core.

Architecture

The Little Man Computer is the standard textbook model of a von Neumann machine, small enough to hold in your head:

  • 100 mailboxes (addresses 00-99), each holding one 3-digit decimal value 000-999. Every mailbox is simultaneously data and one instruction.
  • Accumulator (ACC) - the single 3-digit working register, plus a NEG flag set when a subtraction goes below zero (tested by BRP).
  • Program counter (PC) - the 2-digit address of the next instruction.
  • INBOX / OUTBOX - a queue the program reads with INP and a tape it appends to with OUT.

Instructions are decimal: the hundreds digit is the opcode, the last two digits an address.

CodeMnemonicEffect
1xxADDACC ← ACC + mailbox[xx]
2xxSUBACC ← ACC − mailbox[xx]
3xxSTAmailbox[xx] ← ACC
5xxLDAACC ← mailbox[xx]
6xxBRAPC ← xx
7xxBRZPC ← xx if ACC = 0
8xxBRPPC ← xx if ACC ≥ 0 (NEG clear)
901INPACC ← next INBOX value
902OUTappend ACC to the OUTBOX
000HLTstop

The shared debugger's lmc decoder turns each mailbox back into these mnemonics in the disassembly view, so you can watch the fetch-decode-execute cycle one instruction at a time.