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.
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:
- 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.
- Decode: the control unit works out what the instruction in the CIR means.
- Execute: the instruction is carried out.
| Instruction | What it does | Code |
|---|---|---|
| INP | Input a number into the ACC | 901 |
| OUT | Output the number in the ACC | 902 |
| LDA x | Load the value at address x into the ACC | 5xx |
| STA x | Store the ACC at address x | 3xx |
| ADD x | Add the value at address x to the ACC | 1xx |
| SUB x | Subtract the value at address x from the ACC | 2xx |
| BRA x | Always branch (jump) to x | 6xx |
| BRZ x | Branch to x if the ACC is zero | 7xx |
| BRP x | Branch to x if the ACC is zero or positive | 8xx |
| HLT | Stop the program | 000 |
| x DAT n | Label 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.