Little Man Computer
What is Little Man Computer?
The Little Man Computer (LMC) is an instructional model of a computer, created by Dr. Stuart Madnick in 1965. It is used to teach students, because it models a simple von Neumann architecture computer. This has all of the basic features of a modern computer. It can be programmed in machine code or assembly code. Here are some of the common codes.
How does it work?
To execute a program, the little man performs these steps:
- Check the Program Counter for the mailbox number that contains a program instruction (i.e. zero at the start of the program)
- Fetch the instruction from the mailbox with that number.
- Each instruction contains two fields: An opcode (indicating the operation to perform) and the address field (indicating where to find the data to perform the operation on).
- Increment the Program Counter (so that it contains the mailbox number of the next instruction)
- Decode the instruction.
- If the instruction utilises data stored in another mailbox then use the address field to find the mailbox number for the data it will work on, e.g. 'get data from mailbox 42')
- Fetch the data (from the input, accumulator, or mailbox with the address determined in step 4)
- Execute the instruction based on the opcode given
- Branch or store the result (in the output, accumulator, or mailbox with the address determined in step 4)
- Return to the Program Counter to repeat the cycle or halt
Little man computer - Wikipedia
Instruction Set
- LOAD
- mnemonic - LDA
- Load the contents of the given mailbox onto the accumulator (calculator). Note: the contents of the mailbox are not changed.
- mnemonic - LDA
- STORE
- mnemonic - STA
- Store the contents of the accumulator (calculator) to the mailbox of the given address. Note: the contents of the accumulator are not changed.
- mnemonic - STA
- ADD
- mnemonic - ADD
- Add the contents of the given mailbox onto the accumulator (calculator). Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for add instructions that cause sums larger than 3 digits.
- SUBTRACT
- mnemonic - SUB
- Subtract the contents of the given mailbox from the accumulator (calculator). Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for subtract instructions that cause negative results -- however, a negative flag will be set so that BRP can be used properly (see below).
- INPUT
- mnemonic - INP
- Copy the value from the "in box" onto the accumulator (calculator).
- OUTPUT
- mnemonic - OUT
- Copy the value from the accumulator (calculator) to the "out box". Note: the contents of the accumulator are not changed.
- mnemonic - OUT
- END
- mnemonic - HLT
- Causes the Little Man Computer to stop executing your program.
- mnemonic - HLT
- BRANCH IF ZERO
- mnemonic - BRZ
- If the contents of the accumulator (calculator) are 000, the PC (program counter) will be set to the given address. Note: since the program is stored in memory, data and program instructions all have the same address/location format.
- mnemonic - BRZ
- BRANCH IF ZERO OR POSITIVE
- mnemonic - BRP
- If the contents of the accumulator are 000 or positive (i.e. the negative flag is not set), the program counter will be set to the given address. Note: since the program is stored in memory, data and program instructions all have the same address/location format.
- mnemonic - BRP
- BRANCH ALWAYS
- mnemonic - BRA
- Set the contents of the accumulator (calculator) to the given address. Note: since the program is stored in memory, data and program instructions all have the same address/location format.
- mnemonic - BRA
- DATA LOCATION
- mnemonic - DAT
- When compiled, a program converts each instruction into a three-digit code. These codes are placed in sequential mailboxes. Instead of a program component, this instruction will reserve the next mailbox for data storage.
- mnemonic - DAT