Friday, 6 Mar 2026

Little Man Computer Guide: Assembly Programming Basics

Understanding the Little Man Computer

Developed in 1965 by Professor Stuart Madnik, the Little Man Computer (LMC) remains an essential educational tool for understanding computer architecture. This simplified model visualizes a computer as a "little man" processing instructions in a mailroom-like environment. Peter Higgson's popular simulator at University College London makes these concepts tangible by demonstrating how CPUs execute assembly language through its limited instruction set. Unlike high-level languages like Python, LMC requires explicit data movement commands, teaching core programming principles through constraint-based problem solving.

Why LMC Matters Today

Despite its simplicity, LMC effectively demonstrates the von Neumann architecture still used in modern computers. Advanced computer science courses continue to include LMC programming because it:

  • Reveals how CPUs interact with RAM
  • Teaches fundamental programming logic
  • Demonstrates instruction execution cycles
  • Provides hands-on assembly experience

The LMC's 11-instruction set forces programmers to build complex operations from basic commands. For example, multiplication requires repeated addition since no dedicated multiply operation exists. This constraint highlights how all programming ultimately reduces to fundamental processor operations.

Core LMC Architecture and Instruction Set

The LMC simulator consists of three key components:

  1. CPU with accumulator, program counter, and instruction register
  2. RAM with 100 memory locations (mailboxes)
  3. I/O for user input and output

The Essential Instruction Set

Each LMC operation has a numeric code that gets converted to binary during assembly:

MnemonicCodeFunction
INP901Input to accumulator
OUT902Output accumulator
STA3xxStore accumulator to address xx
LDA5xxLoad from address xx to accumulator
ADD1xxAdd value at xx to accumulator
SUB2xxSubtract value at xx from accumulator
BRZ7xxBranch to xx if accumulator is zero
BRP8xxBranch to xx if accumulator positive
BRA6xxUnconditional branch to xx
HLT000Halt program
DAT-Data declaration

Critical limitation: LMC uses only direct addressing. You cannot directly use values like ADD 3 - you must store the value 3 in memory first using DAT and reference its location.

The Accumulator's Central Role

The accumulator is the CPU's temporary working memory. Every operation interacts with it:

  • INP places values directly into the accumulator
  • Arithmetic operations modify the accumulator's contents
  • OUT displays the accumulator's current value
  • STA copies the accumulator to RAM
  • LDA overwrites the accumulator with RAM contents

Understanding data flow through the accumulator is essential for writing efficient LMC programs. Well-optimized code minimizes unnecessary memory operations by leveraging the accumulator strategically.

Practical LMC Programming Examples

Let's implement the video's programming challenges. These demonstrate core concepts while building problem-solving skills.

Adding Two Numbers

INP      // Input first number to accumulator
STA NUM1  // Store to NUM1 (address 09)
INP      // Input second number to accumulator
ADD NUM1 // Add NUM1 to accumulator
OUT      // Output result
HLT      // Stop
NUM1 DAT  // Data storage at address 09

Optimized version using one variable:

INP      // First number to accumulator
STA TEMP  // Store temporarily
INP      // Second number to accumulator
ADD TEMP // Add first number
OUT      // Output sum
HLT
TEMP DAT

Adding Five Numbers

     LDA TOTAL  // Load current total
     ADD NEXT   // Add next number
     STA TOTAL  // Store updated total
     ...
TOTAL DAT 0
NEXT  DAT

Key insight: Reuse the same memory location for sequential inputs rather than declaring five separate variables. After each INP, immediately add to the running total.

Adding Three and Subtracting Two

... // Code adds first three numbers to TOTAL
INP       // Fourth number
STA SUB1  // Store for subtraction
INP       // Fifth number
STA SUB2
LDA TOTAL
SUB SUB1  // Subtract fourth
SUB SUB2  // Subtract fifth
OUT
HLT
SUB1 DAT
SUB2 DAT

Pro tip: Use descriptive labels like SUB1 instead of generic names. This improves readability in complex programs.

Adding Three and Doubling

... // Code adds three numbers to TOTAL
LDA TOTAL
ADD TOTAL // Double by self-addition
OUT
HLT

Why this works: Adding a value to itself is equivalent to multiplication by 2, avoiding the lack of a multiply instruction.

Debugging and Simulation Tips

  1. Step execution: Use the simulator's step function to observe the fetch-execute cycle
  2. Watch the accumulator: Its value changes after every instruction
  3. Verify memory: Check if variables contain expected values after stores
  4. Common errors:
    • Forgetting DAT declarations
    • Attempting immediate addressing (ADD 3 instead of ADD THREE)
    • Not resetting the program counter between runs

Essential practice: After writing any program, step through it while tracking:

  • Current instruction
  • Accumulator value
  • Relevant memory locations
  • Program counter address

Next Steps in LMC Mastery

Having mastered these fundamentals, you're ready for advanced concepts:

  • Branching: Implement loops with BRA and conditional logic with BRZ/BRP
  • Subroutines: Create reusable code sections
  • Algorithms: Develop sorting routines or mathematical functions
  • Optimization: Reduce instruction count and memory usage

Actionable Learning Checklist

  1. Write and test the addition program
  2. Implement the five-number addition challenge
  3. Create the add-three-subtract-two program
  4. Modify a program to use fewer variables
  5. Step through each program observing register changes

Recommended resources:

  • Peter Higgson's LMC Simulator (web-based)
  • "The Elements of Computing Systems" textbook
  • ARM Assembly Basics (next-step after LMC)
  • Structured Programming with LMC (research paper)

Which LMC concept have you found most challenging to implement? Share your experience in the comments below.