LMC simulators are based on the Little Man Computer (LMC) model of a computer, created by Dr. Stuart Madnick in 1965. The LMC simulator is generally used to for educational purposes, because it models a simple Von Neumann architecture computer which has all of the basic features of a modern computer. It is programmed using assembly code.
The LMC simulator demonstrates how assembly code is processed by the CPU using the Fetch, Decode and Execute (FDE) Cycle. It shows the impact of the FDE cycles on the main registers found inside the CPU:
- The PC (Program Counter),
- The CIR (Current Instruction Register),
- The MAR (Memory Address Register),
- The MDR (Memory Data Register),
- The Accumulator.
The LMC simulator also demonstrates how the CPU interacts with the Random Access Memory (RAM) and how both data and instructions are stored in the RAM. On our LMC simulator the RAM consists of 100 memory cells (also called mailboxes). Each cell has a unique memory location (a number between 00 and 99).
Most assembly instructions consist of an opcode and an operand.
When coding in assembly code we use mnemonics (e.g. INP, ADD, SUB, LDA, STA, etc.) for the opcode of the instruction. A lookup table (See at the end of this blog post) is used to check the corresponding opcode matching a mnemonic. With the LMC simulator, the operand is a memory location (Direct Addressing) of where the data used by the instruction can be fetched from (e.g. LDA, ADD, SUB instructions) or needs to be stored (e.g. STA instruction).
Labels can also be used instead of hard coding memory locations in the code. Labels are extremely useful when using branching instructions (BRA, BRZ, BRP), as they can be used to locate a specific instruction in the code/RAM. They can also be used to name memory cells in the RAM used to temporary store values. (Similar to the use of variables in a high level code).
LMC simulators can be used to implement simple programs to perform basic mathematical operations such as adding or subtracting numbers, comparing or sorting numbers, etc.Launch our online LMC SimulatorOpen in new tab/window
You will find on this blog a range of LMC challenges that you can complete using our online LMC simulator:
- 12 LMC mini challenges
- LMC Max function
- LMC Count down
- LMC Multiplication
- LMC Triangular Numbers
- LMC Factorial Challenge
- LMC Burglar Alarm
LMC Instruction Set / Lookup Table
Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.
|INP||INPUT||Retrieve user input and stores it in the accumulator.||901|
|OUT||OUTPUT||Output the value stored in the accumulator.||902|
|LDA||LOAD||Load the Accumulator with the contents of the memory address given.||5xx|
|STA||STORE||Store the value in the Accumulator in the memory address given.||3xx|
|ADD||ADD||Add the contents of the memory address to the Accumulator||1xx|
|SUB||SUBTRACT||Subtract the contents of the memory address from the Accumulator||2xx|
|BRP||BRANCH IF POSITIVE||Branch/Jump to the address given if the Accumulator is zero or positive.||8xx|
|BRZ||BRANCH IF ZERO||Branch/Jump to the address given if the Accumulator is zero.||7xx|
|BRA||BRANCH ALWAYS||Branch/Jump to the address given.||6xx|
|HLT||HALT||Stop the code||000|
|DAT||DATA LOCATION||Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.|