The Little Man Computer PDF
The Little Man Computer PDF
2
The Little Man Computer
3
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.
4
The Little Man Computer
5
Mailboxes: Address vs. Content
• Addresses are consecutive
• Content may be
– Data or
– Instructions
Address Content
6
Mailboxes: Content - Instructions
• Op code
– Operation code
– Arbitrary mnemonic
• Operand
– Object to be manipulated
• Data or
• Address of data
Address Content
Op code Operand
7
Calculator
• The calculator can be used to enter and
temporarily hold numbers, and also to add
and subtract.
8
Hand Counter
• There is a two-digit hand counter, the
type that you can click to increment the
count.
9
Little Man
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.
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.
13
Instruction Set
Arithmetic 1xx ADD
2xx SUB
5xx LOAD
902 OUTPUT
14
Input/Output
• Move data between calculator and in/
out baskets
Content
Op Code Operand
(address)
IN (input) 9 01
OUT (output) 9 02
15
LMC Input/Output
IN
OUT
16
Internal Data Movement
• Between mailbox and calculator
Content
Op Code Operand
(address)
STO 3 xx
(store)
LDA 5 xx
(load)
17
LMC Internal Data
LDA
STO
18
Arithmetic Instructions
• Read mailbox
• Perform operation in the calculator
Content
Op Code Operand
(address)
ADD 1 xx
SUB 2 xx
19
LMC Arithmetic Instructions
ADD
SUB
20
Simple Program: Add 2 Numbers
21
Program to Add 2 Numbers:
Using Mnemonics
Mailbox Mnemonic Instruction Description
05 COB ;stop
99 DAT 00 ;data
22
Program to Add 2 Numbers
Mailbox Code Instruction Description
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.
24
Program Control
• Branching
– executing an instruction out of sequence
– Changes the address in the counter
• Halt Content
Op Code Operand
(address)
BR (Jump) 6 xx
BRZ (Branch on 7 xx
Calc=0)
BRP (Branch on 8 xx
Calc=+)
25
Program control
While value = 0 Do
Task;
NextStatement
26
Extended Instruction Set + Mnemonics
Arithmetic 1xx ADD
2xx SUB
Data Movement 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
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
29
Fetch Portion of
Fetch and Execute Cycle
2. He walks over to
the mailbox that
corresponds to the
location counter
30
Fetch, cont.
31
Execute Portion
32
Execute Portion
33
Execute, cont.
34
von Neumann Architecture (1945)
35
von Neumann Architecture (1945)
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
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
40