The Little Man Computer (LMC)

The Little Man Computer (LMC) is an instructional model of a computer, created by Dr. Stuart Madnick in 1965. It models a von Neumann architecture computer, which has all the basic features of a modern computer. At the same time, it is simple enough to be understood and programmed by high school students. It shows how computers carry out complex tasks by executing a few simple instructions really fast, making them seem to do fascinating things and appear intelligent.

This tool is an animated simulation of the LMC and is designed to be simple and intuitive to use. It allows the user to:

  • Understand the basics of how a computer's Central Processing Unit (CPU) works
  • Understand an instruction set and opcodes
  • Programme the LMC in a language similar to assembly language
  • Compile the programme into LMC "machine code"
  • Follow the programme execution

Users can write their own programmes to carry out operations such as addition, multiplication, etc. The LMC programmes written by the user can be saved to the computer as .lmc files. The download file comes with a programme that counts down from a given input to zero.

image

Download

Little_Man_Computer.xlsx

Description of the Little Man Computer

The little man computer consists of a little man living in a room and has 3 parts: a filing cabinet or memory, a basic calculator that can perform addition and subtraction and a counter. The room has an input and output window for exchanging data with the external world. The memory contains a set of 100 storage locations labelled 00 to 99. Each of these can store a piece of information containing a 3-digit number. The first digit of this number is the op code or instruction code that tells the little man the task to be done, and the remaining digits make up the memory location relevant to that task. The counter tells the little man the address in which the next task is located. The little man increments this after finishing each task.

image

The instruction codes (also known as instruction set) for the Little Man are as follows:

1 - Add: Add the value at the location specified by the last 2 digits to the value in the calculator

2 - Subtract: Subtract the value at the location specified by the last 2 digits from the value in the calculator

3 - Store: Put the value in the calculator into the specified memory location

4 - Input: Take the value in the input and place it into the calculator

5 - Load: Load value at the location specified by the last 2 digits into the calculator

6 - Branch: Jump to the memory address specified by the last 2 digits and execute the instruction kept there in the next step

7 - Branch if zero: If the number in the calculator is 0, jump to the memory address specified by the last 2 digits and execute the instruction kept there in the next step

8 - Branch if positive: If the number in the calculator is positive, jump to the memory address specified by the last 2 digits and execute the instruction kept there in the next step

9 - Output: Copy the value in the calculator into the output

0 - Relax: Halt execution and take a break

Editing an LMC programme

The following figure shows the parts and functions of the programme editor.

image

The editor seciton has 5 columns:

#: Memory address where the instruction will be loaded to.

Label: This works like a bookmark for the programme to help give a meaning to the code

Instuction:Instuction selectable through a dropdown list

Arg: Argument that the instuction requires.

Comment: Line comment to help document the code

The download file contains a sample programme in the editor to help understand these concepts.

Executing an LMC programme

After editing a programme, click the "Load to CPU" button to compile the code into LMC assembly language and load it into the memory of the computer.

Any inputs needed by the programme should be entered into the "Inputs" column.

Choose the radio button to run the programme slow or fast and then use the "Run" button to execute the code. As the code is executed, the line corresponding to the current instruction is highlighted, helping the user follow the execution. Clicking the "Abort" button will halt execution.

Outputs generated by the programme will appear under the "Outputs" column.

Sample LMC programmes

The following sample programmes can be downloaded and used in this simulator

Add.lmc: Programme to add 2 input numbers

Subtract.lmc: Programme to subtract second input from the first

Sqaure.lmc: Programme to calculate the square of an input number

FindMax.lmc: Programme to find the maximum of 2 numbers

Countdown.lmc: Programme to countdown from an input to zero.