Bytesize CS

Little Man Computer

Write assembly code, then run it and watch the CPU fetch, decode and execute each instruction. Pass all 10 challenges to earn a pioneer card. New to assembly? Start with the Assembly course, which teaches every instruction step by step.

Each INP takes the next value, e.g. 5, 3 Output
Memory (100 boxes)

Blue: the address in the PC (the next instruction). Dashed orange: the address in the MAR.

How the Little Man Computer works

The Little Man Computer (LMC) is a simple model of a CPU with 100 memory boxes (addresses 0 to 99) and one register for calculations, the accumulator (ACC). Your program is loaded into memory, then the CPU repeats the fetch–decode–execute cycle:

  1. Fetch: the address in the PC is copied to the MAR, the instruction at that address is copied into the MDR and then the CIR, and the PC goes up by 1.
  2. Decode: the control unit works out what the instruction in the CIR means.
  3. Execute: the instruction is carried out.
InstructionWhat it doesCode
INPInput a number into the ACC901
OUTOutput the number in the ACC902
LDA xLoad the value at address x into the ACC5xx
STA xStore the ACC at address x3xx
ADD xAdd the value at address x to the ACC1xx
SUB xSubtract the value at address x from the ACC2xx
BRA xAlways branch (jump) to x6xx
BRZ xBranch to x if the ACC is zero7xx
BRP xBranch to x if the ACC is zero or positive8xx
HLTStop the program000
x DAT nLabel a memory box x holding the value n (0 if left out)

A line can start with a label, e.g. loop LDA total, and branches can jump to it. Use labels for your data too: put total DAT after HLT, so the program never runs into it. Anything after // is a comment.