The Little Man Computer (LMC) This is a simplified model of a Central
Unit and can you to understand how one works.
A program is written in
language and when this is
the LMC program converts each instruction into a three-digit
code. These codes are placed in
memory addresses, along with any data that makes up the program.
Each memory slot has an address between 00 and 99. Each
slot can therefore contain either one 3-digit instruction OR some data.
The processor works by
an instruction from memory,
it and then fetching the next instruction etc. This is called the fetch-execute cycle.
The
accumulator box displays the contents of the accumulator, either loaded data or the results of a
.
The LMC has one input, where data is entered, and one outout (from the
).
The
counter stores the memory address of the next instruction that is going to be
.
The LMC Instruction Set The machine code for the LMC is very simple. Each 3 digit instruction has 1 digit, the OP-code, which tells the LMC which instruction to execute, and 2 extra digits.
For the 7 instructions below, the 2 extra digits show the memory address where the data is stored or where the program counter is to branch to.
LOAD STORE ADD SUBTRACT BRANCH IF ZERO BRANCH IF ZERO OR POSITIVE BRANCH ALWAYS While the program is running these 7 instructions the
MEM address box displays the address the instruction is referring to and the
MEM data box displays the data stored at that address.
For the 2 instructions below the 2 extra digits define if the instruction is an
(01) to the accumulator or an output (02) from it.
While the program is running these 2 instructions or the END instruction, the
MEM address box and the
MEM data box displays can therefore be ignored.
Details of the full instruction set mnemonic - LDA
machine code - 5
Action - Load the contents of the given memory slot onto the
.
STORE
mnemonic -
machine code - 3
Action - Store the contents of the accumulator to the memory slot of the given address.
mnemonic - ADD
machine code - 1
Action - Add the contents of the given memory slot onto the accumulator.
SUBTRACT
mnemonic -
machine code - 2
Action - Subtract the contents of the given memory slot from the accumulator.
mnemonic - INP
machine code - 901
Action - Copy the value from the "in box" onto the accumulator.
OUTPUT
mnemonic -
machine code - 902
Action - Copy the value from the accumulator to the "out box".
END
mnemonic -
machine code - 000
Action - Causes the Little Man Computer to stop executing the program.
BRANCH IF ZERO
mnemonic -
machine code - 7
Action - If the contents of the accumulator are 000, the PC (program counter) will be set to the given address.
BRANCH IF ZERO OR
mnemonic - BRP
machine code - 8
Action - If the contents of the accumulator are
or positive, the PC (program counter) will be set to the given address.
BRANCH ALWAYS
mnemonic -
machine code - 6
Action - Set the contents of the PC (program counter) to the given address.
DATA LOCATION
mnemonic -
machine code - (the data)
Action - none, instead this instruction will reserve the next memory slot for
storage.