Little Man Computer

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Little Man Computer

The Little Man Computer consists of a closed room, in which the Little Man lives. The
Little Man can interact with the external world through 2 windows, one called "Input"
through which he can receive instructions and another called "Output" through which
he can send out messages. Inside the room, the little man has access to 100
mailboxes (storage locations), an accumulator (basic calculator) and a counter.
Finally, he has a little corner to relax. See picture below.

The job of the little man is to execute programs from the memory, one step at a time.
The little man has a counter to keep track of the steps. When asked to execute a
program, the Little Man goes to the memory location '00' and starts by executing the
instruction located there. Once he is done, he increments the counter and proceeds
to the next memory location and so on till he is asked to relax. All data and
instructions are in the form of 3 digit numbers. The first digit represents an instruction
and the last 2 digits can specify a memory location, depending on the instruction.
Components & Physical Layout

Reset (Start) Button:


100 mailboxes
 Address 00 - 99
The operator of the LMC (not the Little Man)
 Each holds 3-digit decimal number
presses the START BUTTON to zero the Calculator
Instruction Counter and ring a bell which wakes  Enter number
up the Little Man, so he can start executing the  Temporarily hold number
program which has previously been stored in  Add and Subtraction
the mailboxes.  Display 3 digits
Hand counter
Instruction Counter:  Reset button
 Instruction counter
This display contains the number of the mailbox  Little Man
address in which the next instruction is stored.  In/Out Basket

The Little Man can change the number in the instruction counter (usually by
incrementing, but sometimes by replacement), and the user of the LMC can reset the
Instruction Counter to 00 using the start button.

Calculator:

Performs simple arithmetic (addition and subtraction only), and used for temporary
storage of a single three digit number. Its display is limited to three digits.

The calculator has ten numerical keys (0-9), and two operation keys (+ and -).

The calculator also has two lights which can be seen by the Little Man. One of these
lights turns on whenever the number being displayed is exactly ZERO. The other light
turns on whenever the number being displayed is positive (the number zero is
considered a positive number). Thus when zero is displayed on the calculator, both
lights will be on. These lights are sometimes referred as flags.

Mailboxes:

Mailboxes are identified by two-digit numbers (00 - 99) and each can hold a single
slip of paper containing a single three digit number (either data or instruction).

Communication with outside World


A user outside of the room can communicate with the Little Man by either

 Putting a 3-digit into the in basket, or


 Retrieving a 3-digit from the out basket

Apart from the reset button, all communication between the LMC and the outside
world takes place using 3-digit numbers via In or Out baskets (trays).
Operation
We would like the LMC to do some useful work, so we define a small group of
instructions that he can perform. The 3 digit numbers are used to give instructions to
the Little Man.

The first digit of it is used to tell which operation to perform (opcode). If the operation
requires the LM to use a particular mailbox, we can use the last two digits to specify
the mailbox address that the Little Man is required to store / retrieve data, or to go to.

• Op code
325 – Operation code
– Arbitrary mnemonic
operation code mailbox address
(opcode) (operand) • Operand
– Object to be manipulated
• Data or
• Address of data
Instruction Set
mnemonic meaning opcode operand
add content of address xx to
1xx ADD 1 xx
calculator value
Arithmetic
subtract content of address xx
2xx SUB 2 xx
from calculator value
store calculator value into
3xx STO 3 xx
address xx
Data Movement 4xx DAT 1 store the value xx into calculator 4 xx
load content of address xx into
5xx LDA 5 xx
calculator
move data from in basket to
901 IN 9 01
calculator
Input / Output
move data from calculator to out
902 OUT 9 02
basket
set the instruction counter to xx,
6xx BR thus effectively jump to the 6 xx
instruction in address xx
IF the calculator value is zero,
THEN set the instruction counter
7xx BRZ 7 xx
Branching to xx, thus effectively jump to the
instruction in address xx
IF the calculator value is positive,
THEN set the instruction counter
8xx BRP 8 xx
to xx, thus effectively jump to the
instruction in address xx
Machine Control
000 STP / COB stop - the Little Man rests 0 ignore
(coffee break)

A user can write programs using the instructions above and loads it into the Little
Man Computer's memory (i.e. the mail boxes) for execution.

1
This instruction (DAT) is added by us as needed. (R.T.Sirmen)
Executing a Program
The companioning Excel simulation can be used for writing and executing programs.
To actually run an LMC program we must carry out the following steps:

1. Load the instructions into the mailboxes, starting with mailbox 00.

2. Place the data to be used by the program in the IN basket, in the order in which
the program will use these data.

3. Press the RESET / START BUTTON to set the Instruction Counter to 00 and also
to wake the Little Man up. Then;

a. The Little Man looks into the Instruction Counter


b. The Little Man finds the mailbox whose address has the value in the
Instruction Counter and fetches the 3-digit number from the mailbox
c. The Little Man executes the instruction found in the mailbox
d. The Little Man goes over to increase the instruction counter by 1
e. The Little Man repeats the sequence by going back to the step a
f. The Little Man stops and takes a rest as he encounters the stop instruction
Instruction Execution Cycle
• Fetch : Little Man finds out what instruction he is to execute

• Execute : Little Man performs the task

Fetching:

1. Little Man reads the address from


the instruction counter

2. He walks over to the mailbox that


corresponds to the instruction
counter

3. And reads the number on the slip


of paper (he puts the slip back in
case he needs to read it again
later)
Execution:

• The execution portion of each instruction is, of course, different for every instruction.
• However, even here, there are many similarities.
• The load instruction is typical.

1. The Little Man goes to the


address specified in the
instruction he just fetched.

2. He reads the number in that


mailbox (he remembers to replace it
back in case he needs it later).

3. He walks over to the calculator


and punches the number in.

4. He walks over to the instruction


counter and clicks it, which gets him
ready to fetch the next instruction.
von Neumann Architecture (1945)
 John von Neumann is usually considered to be the developer of modern
computer architecture.

 The major guidelines that define a von Neumann architecture are:


 Stored program concept - memory holds both programs and data
 Memory is addressed linearly
 Memory is addressed without regard to content

 Instructions are executed sequentially unless an instruction or an outside event


causes a branch to occur.

 von Neumann defined the functional organization of a computer to be made up of


 A control unit that executes instructions
 An arithmetic logic unit that perform arithmetic and logical calculations
 Memory

 If you check over the guidelines and organization just described, you will observe
that the LMC is an example of a von Neumann architecture.
• The LMC provides a model of the workings of a computer.
• The LMC works by following simple instructions, which are described by
numbers.
• Some of these instructions cause the LMC to change the order in which
instructions are executed.
• Both data and instructions are stored in individual mail slots. There is no
differentiation between the two except in the context of the particular operation
taking place.
• The LMC follows the fetch-execute cycle.
• Normally the LMC executes instructions sequentially from the mail slots except
when he encounters a branching instruction.
The LMC and a real Computer
The relationship between the LMC model and a physical computer is as
follows:

- The Little Man himself is like the control unit of the CPU

Little Man CU

- The mailboxes represent the Random Access Memory (RAM) which is


used for loading programs and data for immediate use by the CPU

Mailboxes RAM

- The calculator represents the Arithmetic Logic Unit (ALU) of the CPU

Calculator ALU

- The input tray represents the various input devices connected to the CPU,
which include keyboard, mouse, and so on
In basket Input devices

- The output tray represents the various output devices connected to the
CPU, which include monitors, speakers, and so on

Out basket Output devices

- The LMC program is like a program in assembly language that a CPU


understands
LMC Assembly
program program
Sample Programs
Add 2 Numbers

start

input 1st #

store # in 99

input 2nd #

add # in 99

output

stop

Mailbox Mnemonic Code Instruction Description


00 IN 901 input 1st number
01 STO 99 399 store data
02 IN 901 input 2nd number
03 ADD 99 199 add 1st # to 2nd #
04 OUT 902 output result
05 COB 000 stop

99 holds data
Subtract 2 numbers

start

input 1st #

store # in 10

input 2nd #

subtract # in 10

output

stop

Mailbox Mnemonic Code Instruction Description


00 IN 901 input 1st number
01 STO 10 310 store # in 10
02 IN 901 input 2nd number
03 SUB 10 210 subtract 1st # from 2nd #
04 OUT 902 output result
05 COB 000 stop

10 holds data
Find positive difference of 2 numbers

start subtract # in 10

input 1st #
result load # in 10
>= 0 F
store # in 10
T subtract # in 11

output
input 2nd #

store # in 11 stop

Mailbox Mnemonic Code Instruction Description


00 IN 901 input 1st number
01 STO 10 310 store # in 10
02 IN 901 input 2nd number
03 STO 11 311 store # in 11
04 SUB 10 210 subtract 1st # fm 2nd #
05 BRP 08 808 jump to 08 if positive
06 LDA 10 510 if negative reverse
07 SUB 11 211 subtract 2nd # fm 1st #
08 OUT 902 output result
09 COB 000 stop
10 holds 1st number
11 holds 2nd number
Countdown to zero

Mailbox Mnemonic Code Instruction Description


00 IN 901 input decrement value
01 STO 10 310 store value in 10
02 IN 901 input starting #
03 SUB 10 210 subtract decrement fm #
04 OUT 902 output remaining #
05 BRZ 07 707 if zero reached go to stop
06 BR 03 603 loop back
07 COB 000 stop

10 holds decrement value


Maximum of 2 numbers

Mailbox Mnemonic Code Instruction Description


00 IN 901 input 1st #
01 STO 21 321 store in 21
02 IN 901 input 2nd #
03 STO 22 322 store in 22
04 SUB 21 221 subtract 1st # fm 2nd #
05 BRP 09 809 if positive go to 09
06 LDA 21 521 load 1st #
07 OUT 902 output #
08 COB 000 stop
09 LDA 22 522 load 2nd #
10 OUT 902 output #
11 BR 08 608 go to stop

21 holds 1st number


22 holds 2nd number
Square a number

Mailbox Mnemonic Code Instruction Description


00 DAT 01 401 load 1 into calculator
01 STO 21 321 store 1 in 21
02 DAT 00 400 load 0 to calculator
03 STO 24 324 initialize sum
04 IN 901 get # to square
05 STO 22 322 store # in 22
06 STO 23 323 initialize counter
07 LDA 24 524 load previous sum
08 ADD 22 122 add # in 22 to sum
09 STO 24 324 save new sum in 24
10 LDA 23 523 load counter
11 SUB 21 221 subtract 1 - ie decrement
12 STO 23 323 save new counter val in 23
13 BRZ 15 715 If 0 go to end
14 BR 07 607 loop back
15 LDA 24 524 load sum
16 OUT 902 output sum
17 COB 000 stop

21 holds 1 for decrementing


22 holds user input
23 counter
24 holds result of addition

You might also like