Although it is completely inaccurate, it is sometimes convenient to imagine a computer's processing as if it were being managed by a "little man" inside the computer. This (imagined) "little man" behaves following an extremely rigid routine and never performs outside that routine.
An LMC (Little Man Computer) can be imagined to have certain resources available for the little man to use: input and output "trays", a calculator, a collection of numbered "mailboxes", and a counter to keep track of which mailbox the "little man" should look in for his next instruction.
the "little man" can only do a limited number of things:
The only facility for communication between the "little man" and the world outside the "computer room" is by means of a single Input basket (or "tray") and a single Output basket. A single 3 (decimal) digit value is all that will fit in either basket at any one time.
The Counter contains a 2 decimal digit value that can be modified in one of three different ways:
As mentioned earlier, there is a table posted on the wall telling the "little man" exactly what to do depending upon the Instruction value that the "little man" is currently remembering.
|1xy||LOAD||LDA||copy value from Mailbox with the supplied Mailbox number (xy) into the Calculator|
|2xy||STORE||STO||copy value from the Calculator into the Mailbox with the supplied Mailbox number (xy)|
|3xy||ADD||ADD||add the value in the Mailbox at the supplied Mailbox number to the Calculator; set lights|
|4xy||SUBTRACT||SUB||subtract the value in the Mailbox at the supplied Mailbox number from the value in the Calculator; set lights|
|500||INPUT||IN||copy the value currently in the Input basket to the Calculator|
|600||OUTPUT||OUT||copy the value from the Calculator to the Output basket|
|700||HALT||HLT||stop processing; sleep until the Reset button rings the bell|
|800||SKIP_IF_NEG||SKN||increment the Counter an extra time (skip next instruction) if the Calculator Negative indicator is on|
|801||SKIP_IF_ZERO||SKZ||increment the Counter an extra time (skip) if the Calculator Zero indicator is on|
|802||SKIP_IF_POS||SKP||increment the Counter an extra time (skip) if the Calculator Positive indicator is on|
|803||SKIP_NON_ZERO||SKNZ||increment the Counter an extra time (skip) if the Calculator Zero indicator is *NOT* on [not available in all LMC simulators]|
|9xy||JUMP||JMP||set the counter to be the value (xy) (jump to this instruction next)|
|0xy||SUBRTN_CALL||CALL||store 900 + <contents of counter> into Mailbox number (xy-1), then set counter to be value (xy) [not available in all LMC simulators]|
The "little man" continuously repeats the following sequence of three major activities:
As a first step in the fixed routine, the "little man" must get the instruction telling him what he should do next.
The incrementing of the Counter must occur before instruction execution, as will become obvious when we look at instructions whose execution modifies the value in the Counter.
These three major activities are called: Fetch, Increment, and Execute. Every computer does this.
Every instruction in the LMC is encoded as a 3 decimal digit number
How does the "little man" handle instructions that are not on his Instruction Set Table? Notice that any value beginning with "81" has no specified action. "555", "666", "777" and others are not there either. The "little man's" actions (and the actions of a real CPU) are undefined when an unknown instruction code is seen. Windows machines blue-screen with "invalid instruction" when this happens. It is the programmer's responsibility to ensure that this never happens.