The Little Man Computer is a model of a von Neumann architecture computer (the same as most modern computers).
It is extremely simple, with a small instruction set, so is often used to teach students.
This model is programmed in machine code, with instructions in base 10.
An explanation can be found at the bottom of this page, should you need help.
Quick start
Load an example program in the Assembly Code box, hit Assemble
Press Load in the Machine Code box to load the instructions into memory
Press Start in the Controls box to begin execution
When the input box has a red border, enter a number
Wait for the the program's output
Memory
0
1
2
3
4
5
6
7
8
9
0
10
20
30
40
50
60
70
80
90
Configuration
Controls
Current state:
Registers
Input/Output
Machine Code
Invalid input
Assembly Code
Invalid input
Instruction Set
This is the set of instructions understood by the LMC.
Machine Code
Assembly
Description
1xx
ADD xx
Add memory address xx to the accumulator
2xx
SUB xx
Subtract memory address xx from the accumulator
3xx
STA xx
Store the value of the accumulator at memory address xx
5xx
LDA xx
Load memory address xx into the accumulator
6xx
BRA xx
Set the program counter to the address xx
7xx
BRZ xx
Set the program counter to the address xx if the accumulator is zero
8xx
BRP xx
Set the program counter to the address xx if the accumulator is zero or positive
901
INP
Wait for input and put it in the accumulator
902
OUT
Output the value of the accumulator
000
HLT
Halt the program
xxx
DAT xxx
xxx will be loaded into memory as data.
It should not be executed as an instruction.
How it works & how to program it
Shown above is the memory (RAM) of the computer.
It has 99 'slots' which are each able to hold one integer value.
These values can represent either instructions for the computer, or data put there by the running program.
The instructions available are known as the processor's instruction set.
The instruction set for the LMC is tabulated above for reference.
A program can be written for the computer by writing a list of instructions (machine code), ending with 000 to end the program.
Alternatively, it can be written in assembly and translated into machine code using the 'Assemble' button.
Assembly uses mnemonics to refer to different instructions, making the code easier to read.
In assembly, 'labels' can be used to give a name to a memory address by writing the desired name of the label at the beginning of the line.
Any uses of the label will be translated into the associated memory address.
After writing a program in the box above, you must load it into memory with the button labeled 'Load'.
When the computer is started, it runs through the instructions in memory, executing them one by one.
The processor's 'program counter' (also called the 'instruction pointer') stores the address in memory of the instruction to be executed next.
Its value can be changed using the branch instructions (6xx - 8xx in the table), which allow for conditional logic and looping.
The accumulator is a register which is used to perform arithmetic and store inputs given to the program (using instruction 901).
Values can be loaded into it from memory and vice versa using 3xx and 5xx.
Data can be placed in the memory by providing a line in the machine code which does not represent any instruction.
The data is placed in the memory at the same position that it appears in the code, and can be pulled into the accumulator with the load command (5xx) as normal.
You must be careful to prevent data from being executed as an instruction, as doing so will crash the computer.