The Little Man Computer
The Little Man Computer
The goals of todays lecture are:
To get a better understanding of the fetch/execute
cycle
To explore the operations that the computer is
capable of performing
Look at how those operations work together to
provide the computer with its power.
The Little Man Computer
We will begin by introducing a model of the
computer (the LMC); a model that operates in
a very similar way to real computers but that
is easier to understand.
The Little Man Computer
Using this model we will introduce:
a simplified, but typical, set of instructions
that a computer can perform.
we will examine how these instructions are
executed in the LMC
we will examine how these instructions are
combined to form programs.
The Little Man Computer
Mailboxes: Address vs. Content
Addresses are consecutive
Content may be
Data or
Instructions
Address
Content
Mailboxes: Content - Instructions
Op code
Operation code
Arbitrary mnemonic
Operand
Object to be manipulated
Data or
Address of data
Address
Content
Op code
Operand
Calculator
The calculator can be used to enter and
temporarily hold numbers, and also to add
and subtract.
The display on the calculator is three digits
wide.
For this discussion there is no provision made
for negative numbers, or for numbers larger
than three digits.
8
Hand Counter
There is a two-digit hand counter, the
type that you can click to increment the
count.
The reset button for the hand counter is
located outside the mailroom.
We will call the hand counter an
instruction location counter.
9
Little Man
Finally, there is the Little Man. His role
is to perform certain tasks.
10
In and Out Basket
Other than the reset switch on the hand counter, the
only interaction between the LMC and the outside
environment are the In and Out Baskets.
A user can communicate with the LMC by putting a
slip of paper with a three- digit number on it into the
basket, to be read by the LMC.
Similarly, the LMC can write a three-digit number on a
slip of paper and leave it in the out basket, where it
can be retrieved by the user.
11
The Little Man Computer
12
LMC Instruction Set
We would like the LMC to do some useful
work, so we define a small group of
instructions that he can perform.
Each instruction will consist of one digit which
identifies which operation the LMC should
perform we will use the first digit of a three.
If the operation requires the LMC to use a
particular mailbox we can use the other two
digits to specify the mailbox address.
13
Instruction Set
Arithmetic
Data Movement
Input/Output
Machine Control
(coffee break)
1xx
ADD
2xx
SUB
3xx
STORE
5xx
LOAD
901
INPUT
902
OUTPUT
000
STOP
COB
14
Input/Output
Move data between calculator and in/
out baskets
Content
Op Code
Operand
(address)
IN (input)
01
OUT (output)
02
15
LMC Input/Output
IN
OUT
16
Internal Data Movement
Between mailbox and calculator
Content
STO
Op Code
Operand
(address)
xx
xx
(store)
LDA
(load)
17
LMC Internal Data
LDA
STO
18
Arithmetic Instructions
Read mailbox
Perform operation in the calculator
Content
Op Code
Operand
(address)
ADD
xx
SUB
xx
19
LMC Arithmetic Instructions
ADD
SUB
20
Simple Program: Add 2 Numbers
The logic for adding two
numbers in the LMC is
given on the left. Write out
the series of LMC
instructions that
implements this logic.
Assume data is stored in
mailboxes with addresses
>90
Input a #
Store the #
Input a #
Add
Output the
number
21
Program to Add 2 Numbers:
Using Mnemonics
Mailbox
Mnemonic
Instruction Description
00
IN
;input 1st Number
01
STO 99
;store data
02
IN
;input 2nd Number
03
ADD 99
;add 1st # to 2nd #
04
OUT
;output result
05
COB
;stop
99
DAT 00
;data
22
Program to Add 2 Numbers
Mailbox
Code
Instruction Description
00
901
;input 1st Number
01
399
;store data
02
901
;input 2nd Number
03
199
;add 1st # to 2nd #
04
902
;output result
05
000
;stop
99
000
;data
23
An Extended Instruction Set
The instruction set we have specified
does not provide any means for
branching or looping, both of which are
very important constructs for
programming.
We need to extend the instruction set to
provide the LMC to carry out more
complex programs.
24
Program Control
Branching
executing an instruction out of sequence
Changes the address in the counter
Halt
Content
Op Code
Operand
(address)
BR (Jump)
xx
BRZ (Branch on
xx
xx
(ignore)
Calc=0)
BRP (Branch on
Calc=+)
COB (stop)
25
Program control
While value = 0 Do
Task;
NextStatement
45
LDA 90
590 90 is assumed to contain value
46
BRZ 48
748 Branch if the value is zero
47
BR 60
660 Exit loop; jump to NextStatement
48
.
.
.
59
60
BR 45
645 End of Task; loop to test again
Next statement
26
Extended Instruction Set + Mnemonics
Arithmetic
1xx
ADD
2xx
SUB
3xx
STORE (Calc Data to Mailbox)
5xx
LOAD (Mailbox Data to Calc)
BR
6xx
JUMP
BRZ
7xx
BRANCH ON 0
BRP
8xx
BRANCH ON +
Input/Output
901
INPUT
902
OUTPUT
000
HALT
COB
Data Movement
Machine Control
(coffee break)
27
Find Positive Difference of 2 Numbers
00
IN
901
01
STO 10
310
02
IN
901
03
STO 11
311
04
SUB 10
210
05
BRP 08
808
;test
06
LDA 10
510
;if negative, reverse order
07
SUB 11
211
08
OUT
902
;print result and
09
COB
000
;stop
10
DAT 00
000
;used for data
11
DAT 00
000
;used for data
28
Instruction Cycle
Fetch: Little Man finds out what
instruction he is to execute
Execute: Little Man performs the work.
29
Fetch Portion of
Fetch and Execute Cycle
1. Little Man reads the
address from the
location counter
2. He walks over to
the mailbox that
corresponds to the
location counter
30
Fetch, cont.
3. And reads the
number on the slip
of paper (he puts
the slip back in case
he needs to read it
again later)
31
Execute Portion
The execution portion of each instruction is, of
course,different for each instruction.
However, even here, there are many
similarities.
The load instruction is typical.
32
Execute Portion
1. The Little Man goes to the
mailbox address specified
in the instruction he just
fetched.
2. He reads the number in that
mailbox (he remembers to
replace it in case he needs it
later).
33
Execute, cont.
3. He walks over to the
calculator and punches the
number in.
4. He walks over to the location
counter and clicks it, which
gets him ready to fetch the
next instruction.
34
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
35
von Neumann Architecture
(1945)
Instructions are executed
sequentially unless an instruction or
an outside event cause a branch to
occur.
36
Von Neumann Architecture
von Neumann defined the
functional organisation of the
computer to be made up of:
A control unit that
executes instructions
An arithmetic logic unit
that perfrom arithmetic
and logical calculations,
Memory
37
LMC & von Neumann
If you check over the guidelines and
organisation just described, you will observe
that the LMC is an example of a von
Neumann architecture :)
38
Summary
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.
39
Lab Assignments
There are no labs this week because of
the Saint Patricks day bank holiday!
40