DOWNLOAD - LMC version 0.3 (link added 2012/12/02)
Imagine a little man locked inside a mail-sorting office!
In front of him are one hundred pigeonholes. To one side is a serving hatch through which he can accept input from the outside world, and through which he passes output. The little man can write 3-digit codes onto pieces of paper and store them in the pigeon holes according to a set of rules.
The Little Man Computer is a simplified model of computer CPU. It is used as an instructional tool for teaching low-level programming.
The little man has access to a workbench (called the accumulator or ACC) upon which he can store the result of his current calculation, and he has a resettable counter (called the program counter or PC) which keeps track of which pigeonhole he should look for his next instruction.
Computer 'programs' can be written for the Little Man Computer by storing single 3-digit instructions in the pigeonholes. This represents the way a computer stores program data in the addressable main memory before execution. The 3-digit instructions are comprised of a code used to indicate the current instruction to be performed, and a number indicating the address of the pigeonhole from which the little man must retrieve data. Thus the pigeonholes represent addressable memory locations (from 00 to 99), and can contain both instructions and data.
Still awake? Good, then roll your eyes and scroll down...
The instruction set
The Little Man Computer uses the following instructions, which can be either encoded directly into memory addresses or compiled using a simple assembly language.
Instruction Mnemonic Code
ADD ADD 1..
SUBTRACT SUB 2..
STORE STA 3..
LOAD LDA 5..
INPUT INP 901
OUTPUT OUT 902
BRANCH ALWAYS BRA 6..
BRANCH IF ZERO BRZ 7..
BRANCH IF ZERO OR POSITIVE BRP 8..
A value (between 00-99) substituted for the
..corresponds to a memory address.
399means "STORE the current value in the accumulator at memory address 99".
598means "LOAD the value in memory address 98 and put this into the accumulator, so that the accumulator has this new value".
712means "if the value in the accumulator is zero then set the program counter to point at 12, so the next instruction will be taken out of memory address 12".
Mnemonics allow the programmer to use handy short-cuts for instructions, rather than having to rely on numeric codes. This means that we can write programs using an assembly language which is then compiled automatically into the memory addresses.
Labels are ways of referring to memory locations without having to remember the exact value to which a line of code, or a memory address refers. Any code you see that is not part of the instruction set is a label and it can be substituted for a memory address.
DOWNLOAD - LMC version 0.3 (link added 2012/12/02)Example programs
(mail me for more help)
This program starts by taking input from the user. The value entered (which will be between -99 and 999) is then stored at memory address with the label 'NUMBER'. The next command adds the value at address with the label 'NUMBER' onto the accumulator (effectively this program doubles the value entered by the user).
Checks X > Y
SWAP LDA X
This program starts by taking two inputs from the user. The first input is stored in 'X' and the second is stored in 'Y'. The program switches the values of 'X' and 'Y' so that the largest value is always stored in 'X.
START LDA ZERO
LOOP LDA RESULT
ENDLOOP LDA RESULT
RESULT DAT 0
COUNT DAT 0
ONE DAT 1
VALUE DAT 0
ZERO DAT 0
This program repeatedly takes an input and squares that value. For example input '5' and the program will out '25' because 5x5 = 25.
LOOP LDA Y
NEXT BRA LOOP
DISPLAY LDA COUNT
ONE DAT 001
COUNT DAT 000
This program takes two inputs, 'Y' and 'X' respectively and performs integer division upon them. So the output of '8' and '3' is 2, as 3 will go into 8 two times.