# The "Little Man" Computer

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.

## LMC Components

• ### the "Little Man"

the "little man" can only do a limited number of things:
• move about the "computer room" which contains the LMC components following a fixed pattern of actions (call the "Instruction Cycle")
• remember at most one Mailbox number (as described below), one 3 (decimal) digit Data value, and one 3 (decimal) digit Instruction value
• perform other activities within the computer room as part of the "Instruction Cycle" by following instructions posted on the wall as a table of things to do depending upon the first digit of the Instruction value that the "little man" currently remembers

• ### Mailboxes

100 Mailboxes
• each Mailbox has a unique 2 (decimal) digit "Mailbox number" between 00 and 99 inclusive.
• each Mailbox contains a 3 (decimal) digit "Mailbox contents" value.

• ### Calculator

• Addition & Subtraction operation keys
• 3 decimal digit display
• Last operation result indicator (negative, zero, or positive)
• note: the calculator does not allow for signed values; a result indicator will be set to show a arithmetic operation result less than zero, but this result will be displayed as a large value (10's complement) and is not treated as negative by subsequent operations. The calculator has several indicators: Negative, Zero, and Positive (note: Positive is turned on for a positive or a zero result); these indicators are only modified by the arithmetic instructions ADD and SUB

• ### Input and Output Baskets

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.

• ### Counter

The Counter contains a 2 decimal digit value that can be modified in one of three different ways:
• Increment - the "little man" can hit a button which causes the value in the Counter to be incremented by one; this is by far the most common way the Counter value changes.
• Instruction Set - based on an instruction given to the "little man", the "little man" has the ability to set the Counter value to any value supplied as part of the instruction.
• External Reset - the "little man's boss" from outside the computer "room" can click an external button at any time and reset the value in the Counter to 00.

• ### Instruction Set Table of Actions

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.
Instruction Set
Code   Meaning
1xycopy value from Mailbox with the supplied Mailbox number (xy) to the Calculator
2xyreplace the number in the Mailbox at the supplied Mailbox number with the current Calculator value
3xyadd the value in the Mailbox at the supplied Mailbox number to the Calculator
4xysubtract the value in the Mailbox at the supplied Mailbox number from the value in the Calculator
500copy the value currently in the Input basket to the Calculator
600copy the value from the Calculator to the Output basket
700stop processing
800skip the next instruction (i.e. increment the Counter an extra time) if the Calculator Negative indicator is on
801skip the next instruction if the Calculator Zero indicator is on
802skip the next instruction if the Calculator Zero or Positive indicators are on
9xyre-set the counter to (xy)

## LMC Instruction Cycle

The "little man" continuously repeats the following sequence of three major activities:
1. ### Instruction Fetch

As a first step in the fixed routine, the "little man" must get the instruction telling him what he should do next.

1. he reads and remembers the Mailbox number currently displayed as the Counter value
2. he goes over to the Mailbox with the Mailbox number that he is remembering, reads the 3 digit value in that Mailbox, and remembers it as the current Instruction value (forgetting any previous Instruction value that he might have been remembering
2. ### Counter Increment

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.

1. the "little man" pushes a button which increments the Counter value so that it contains the Mailbox number of the sequencially next Mailbox.
3. ### Instruction Execution

1. the "little man" compares the first digit of the Instruction value that he is remembering with the list of values in the "Instruction Set Table" to find out what he should do.
2. he then follows the directions given in the Instruction Set Table that correspond to the first digit of the Instruction value.

These three major activities are called: Fetch, Increment, and Execute. Every computer does this.

## The "Little Man Computer" Instruction Set

In order to know what should be done for any single instruction, the "little man" compares the first digit of whatever Instruction value he is currently remembering with a list of values in an Instruction Set Table and then performs what ever action is indicated in the table next to the matching code.

### Instruction Format

Every instruction in the LMC is encoded as a 3 decimal digit number
• Operation Code - the left-most digit indicates the specific type of action or operation the "little man" should perform.
• Address Field - the right-most two digits generally refer to a Mailbox number which the "little man" is to use in performing the requested operation (however, for some operations, these two digits may be ignored or may have some other special meaning).

## The "No-Match" Problem

One obvious problem that could occur would be how the "little man" should handle an instruction which is not on his Instruction Set Table. Notice that any value beginning with a "0" has no specified action. The "little man's" actions should he encounter such a value as an instruction are unpredictable. It is the programmer's responsibility to ensure that this never happens.