CS Activity · Assembly · Computer Architecture

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

Write code, then click Assemble into RAM.

Input

⌨ Input required! Type a number here and press Enter.

Output

CPU

Program Counter00
Instruction Reg.000
Address Register00
Accumulator000

Arithmetic Logic Unit

Result—

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

MnemonicCodeDescription
LDA x5xxLoad mailbox x into the accumulator
STA x3xxStore the accumulator into mailbox x
ADD x1xxAdd mailbox x to the accumulator
SUB x2xxSubtract mailbox x from the accumulator
INP901Read a number from input into the accumulator
OUT902Send the accumulator to output
BRA x6xxBranch always to address x
BRZ x7xxBranch to x if the accumulator is 0
BRP x8xxBranch to x if the accumulator is 0 or positive
HLT / COB000Stop the program
DAT nnReserve a mailbox holding value n (default 0)

Syntax: label OPCODE operand. Comments start with // or #.