Little Man Computer Simulator
Write LMC assembly, assemble it into RAM, then run or step through it and watch data move between the input, CPU registers, ALU, RAM and output.
Assembly Language Code
Input
Output
CPU
Arithmetic Logic Unit
RAM (100 mailboxes)
Understanding the Little Man Computer
🧠 CPU
The Central Processing Unit fetches instructions from memory, decodes them and executes them, one at a time. It contains the control unit, the ALU and a small set of very fast registers.
🗃️ Registers
Registers are tiny, extremely fast storage locations inside the CPU.
- Program Counter (PC) – address of the next instruction.
- Instruction Register (IR) – the instruction being executed.
- Address Register (AR) – the memory address being read or written.
- Accumulator (ACC) – holds data and results of calculations.
➕ ALU
The Arithmetic Logic Unit performs calculations (add, subtract) and comparisons. In the LMC, ADD and SUB combine the accumulator with a value from memory and send the result back to the accumulator.
💾 RAM
Memory is 100 numbered mailboxes (00–99), each holding a 3-digit number. Instructions and data share the same memory – this is the von Neumann architecture.
🔤 Assembly Language
A human-readable form of machine code using short mnemonics such as LDA and ADD instead of numbers. An assembler translates it into numbers stored in RAM. Labels let you name addresses instead of counting them.
🎯 Operands
An instruction has an opcode (what to do) and an operand (what to do it to). In ADD 12 the opcode is ADD and the operand is address 12. Machine code 112 = opcode 1, operand 12.
🔁 Fetch–Decode–Execute
- Fetch: PC → AR, RAM[AR] → IR, PC + 1.
- Decode: split IR into opcode and operand.
- Execute: carry out the instruction.
Step through a program to watch each stage animate.
📋 Instruction Set
| Mnemonic | Code | Description |
|---|---|---|
| LDA x | 5xx | Load mailbox x into the accumulator |
| STA x | 3xx | Store the accumulator into mailbox x |
| ADD x | 1xx | Add mailbox x to the accumulator |
| SUB x | 2xx | Subtract mailbox x from the accumulator |
| INP | 901 | Read a number from input into the accumulator |
| OUT | 902 | Send the accumulator to output |
| BRA x | 6xx | Branch always to address x |
| BRZ x | 7xx | Branch to x if the accumulator is 0 |
| BRP x | 8xx | Branch to x if the accumulator is 0 or positive |
| HLT / COB | 000 | Stop the program |
| DAT n | n | Reserve a mailbox holding value n (default 0) |
Syntax: label OPCODE operand. Comments start with // or #.