# The Little Man Computer

## A simple imaginary computer for teaching beginners how a computer works.

Most computers in used today have what we call the von Neumann architecture, name after the brilliant mathematician John von Neumann, who is credited with coming up with the concept, although the credit really belongs to German engineer Konrad Zuse who built the first computer the Z1, on these principles.

# How the Little Man Computer Works

Usually the little man computer is described as little guy walking around carrying out tasks. Here is an excerpt from wikipedia explaining it:

• Input/Output — This is where we read and write to the outside world. This is similar to a tape drive. Numbers are read in sequentially and written out sequentially.
• Program Counter — Keeps track of where we are in the program. It contains the address of the memory cell to fetch the next instruction from. It starts at 0 and gets incremented every time an instruction has finished executing.
• Instruction Register — Last instruction fetched is stored here.
• Decoder — Reads content of instruction register. This is kind of analogous to our little man. Depending on instruction red, it will use the red lines to enable or disable other functional units.
• Accumulator — Stores results from calculations as well as data read fro memory or input.
• ALU — The Arithmetic Logic Unit which performs additions and subtractions.

# Executing a Program

Let us look at a very simple program to get a sense of how programs are run on the LMC computer. This program read in two numbers add them together and write out result to ouput.

`       INP          // read from input and put in accumulator       STA total    // store this at address 'total'         INP          // read another number into accumulator       ADD total    // add content of 'total' to accumulator       OUT          // write accumulator content to output       HLT          // halt programtotal  DAT 0        // area storing a number`

# LMC Instruction-Set Overview

Each instruction is a 3-digit number. But usually when programming one deals with letter abbreviations which are easier to remember. Here is a tip on how to read the description below. The `Add` instruction is described as having the number `1xx`. What this really means is that the `xx` are where you put your operand (argument). So `142` is the instruction for adding the contents of memory cell 42 to the contents of the accumulator.

• `SUB` 2xx subtract contents of address `xx` from what is stored in the accumulator. Store result in accumulator.
• `STA` 3xx store accumulator at address `xx` in memory.
• `LDA` 5xx load accumulator with contents at address `xx` in memory.
• `BRA` 6xx jump to location `xx` in program.
• `BRZ` 7xx jump if accumulator is zero
• `BRP` 8xx jump if accumulator is zero or higher (positive).
• `INP` 901 fill accumulator with number from input.
• `OUT` 902 push value in accumulator into output queue.
• `HLT` 000 stop program

# Example of LMC Programs

A common example program which the simulators often come preloaded with is one where a count down is performed. We read a single number from the input and then we write all the numbers from that value down to zero.

`     INP     OUTLOOP BRZ QUIT // Jump to QUIT if accumulator is 0     SUB ONE  // Subtract from accumulator what is stored in ONE     OUT     BRA LOOP // Jump to the memory address labeled LOOPQUIT HLT      // Label this memory address as QUITONE  DAT 1    // Store 1 in this memory address.`
`4 3 2 1 0`

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

## More from Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

## Optimized Solutions: Frequency Counters

Get the Medium app