Lecture Note 05
Lecture Note 05
J 100 mailboxes
J address 00 - 99
J Each holds 3-digit decimal
number
J Calculator
J Enter number
The Little Man Computer J Temporarily hold number
J Add and Subtraction
J Display 3 digits
J Hand counter
J Reset button
J Instruction counter
J Little Man
J In/Out Basket
1 2
The Little Man Computer: Components & Physical Layout The Little Man Computer: Components & Physical Layout
The operator of the LMC (not the Little Man) presses the Performs simple arithmetic (addition and subtraction only)
START BUTTON to zero the Instruction Counter and ring a Used for temporary storage of a single three digit number. The display is
bell which wakes up the Little Man so he can start executing limited to three digits.
the program which has previously been stored in the The calculator has ten numerical keys (0-9) and two operation keys (+ and -).
mailboxes The calculator also has two lights which can be seen by the Little Man.
J Instruction Counter: One of these lights turns on whenever the number being displayed is exactly
zero.
This display contains the number of the mailbox in which the
The other light turns on whenever the number being displayed is positive ( the
NEXT instruction is stored. The Little Man can change the
number ZERO is considered a positive number). Thus when ZERO is
number in the instruction counter (usually by incrementing but displayed on the calculator, both lights will be on.
sometimes by replacement), and the user of the LMC can reset
These lights are sometimes referred to as flags
the Instruction Counter to 00 using the start button
3 4
The Little Man Computer: Components & Physical Layout The Little Man Computer: Communication with outside World
5 6
1
The Little Man Computer: Operation The Little Man Computer: Instruction Set
7 8
The Little Man Computer: Instruction Set The Little Man Computer: Instruction Set
1xx ADD xx Adds the contents of mailbox xx to the 6xx B xx This instruction sets the instruction counter to the
number xx, thus effectively branching to mailbox xx
calculator display.
9 10
The Little Man Computer: Instruction Set The Little Man Computer: Execute Program
To actually run an LMC program we must carry out the following steps.
FORMAT MNEMONIC MEANING J Load the instructions into the mailboxes, starting with mailbox 00.
J Place the data to be used by the program in the IN basket, in the order in
901 INPUT Read a number from the IN basket which the program will use these data.
and key it into the calculator.
J Press the RESET BUTTON to set the Instruction Counter to 00 and to
also wakeup the Little Man. Then
902 OUTPUT Copy the number in the calculator
onto a slip of paper and place it 1. The Little Man looks into the Instruction Counter
into the OUT basket. 2. The Little Man find the mailbox whose address has the value in the
Instruction Counter and fetches the 3-digit number from the mailbox.
3. The Little Man executes the instruction found in the mailbox
4. The Little Man go over to increase the instruction counter by 1
5. The Little Man repeat the by going to 1
11 12
2
The Little Man Computer: Program Example The Little Man Computer: Program Example
Mail Box Map Write a LMC program which adds two numbers together
Mail Box Division: (Memory Map)
99
99 Data
13 14
The Little Man Computer: Program Example The Little Man Computer: The Instruction Cycle
Write a LMC program to find the positive (absolute) difference of two numbers
Mailbox Mnemonic Code
00 IN 901
01 STO 10 310
02 IN 901
03 STO 11 311
04 SUB 10 210
05 BP 08 808
06 LOAD 10 510
07 SUB 11 211
08 OUT 902 The fetch portion of the instruction cycle
09 HALT 000 (LOAD Instruction)
10 DAT 00 000
11 DAT00 000
15 16
The Little Man Computer: The Instruction Cycle The Little Man Computer: The Instruction Cycle
17 18
3
Some Observations Regarding Computer Architecture The Little Man CPU
Buffer
19 20
Programming Languages
21 22
One-to-one translation
Many-to-one translation
Hardware dependence
Hardware independence
Application orientation Systems programming
orientation
General-purpose
Special-purpose
Powerful abstractions
Few abstractions
23 24
4
Terminology An Important Concept
Assembly language
Because an assembly language is a low-level language
– Refers to a type of low-level language that incorporates specific characteristics of a
– Specific to given processor processor, such as the instruction set, operand
addressing, and registers, many assembly languages
Assembler exist.
25 26
27 28
29 30
5
Assembly Language For Conditional Execution In Practice
if (condition) {
body
Because writing application programs in
}
assembly language is difficult, assembly
next statement language is reserved for situations where a
code to test condition and high-level language has insufficient
set condition code functionality or results in poor performance.
branch not true to label
code to perform body
label: code for next statement
31 32
33 34
v – Fills in branch offsets automatically v Programmers must code assembly language equivalents of abstractions
such as
v Consequence: can insert or delete statements v – Conditional execution
without recomputing offsets manually v – Definite and indefinite iteration
v – Procedure call
35 36
6
Beginning, Program & Data in Memory
Summary Reset counter, the Machine in a random state …. 234
MAR 00 901
v Assembler translates assembly language program into binary code 01 310
88
PC 00
v Assembler uses two-pass processing 02 901
v – First pass assigns relative locations +1 03 311
Out Acc. 04 210
v – Second pass generates code 222 05 808
777 06 510
In MDR 07 211
Ctrl
08 902
ALU 09 000
444 444 333 10 000
11 000
37 38
00
PC 00 PC 01
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
222 05 808 102 05 808
901 06 510 901 06 510
In MDR 07 211 In MDR 07 211
Ctrl 102 Ctrl 304
304 08 902 123 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
901 444 333 10 000 901 444 333 10 000
11 000 11 000
39 40
1 0
PC 01 PC 02
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
102 05 808 102 05 808
310 06 510 310 06 510
In MDR 07 211 In MDR 07 211
Ctrl 304 Ctrl 304
123 08 902 123 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
310 444 333 10 000 310 444 333 10 102
11 000 11 000
41 42
7
Instruction Fetch ... 102 Instruction Execution ... 102
MAR MAR
00 901 00 901
01 310 01 310
0 2
0 2
PC 02 PC 03
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
102 05 808 304 05 808
901 06 510 901 06 510
In MDR 07 211 In MDR 07 211
Ctrl 304 Ctrl 123
123 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
901 444 333 10 102 901 444 333 10 102
11 000 11 000
43 44
11
PC 03 PC 04
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
304 05 808 304 05 808
311 06 510 311 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
311 444 333 10 102 311 444 333 10 102
11 000 11 304
45 46
10
PC 04 PC 05
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
304 05 808 202 05 808
210 06 510 102 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
210 444 333 10 102 210 304 102 10 102
11 304 11 304
47 48
8
Instruction Fetch ... 304 Instruction Execution ... 304
MAR MAR
00 901 00 901
01 310 01 310
05
05
PC 05 PC 08
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
202 05 808 202 05 808
808 06 510 808 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
808 304 102 10 102 808 304 102 10 102
11 304 11 304
49 50
08
PC 08 PC 09
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
202
202 05 808 202 05 808
902 06 510 …. 902 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
902 304 102 10 102 902 304 102 10 102
11 304 11 304
51 52
09
PC 09 PC 09
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
202 202
202 05 808 202 05 808
…. 000 06 510 …. 000 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
000 304 102 10 102 000 304 102 10 102
11 304 11 304
53 54
9
Instruction Fetch ... 102
MAR
If the first number is bigger than the first number 00 901
01 310
05
PC 05
………., e.g, the input basket looks like this 02 901
+1 03 311
304 Out Acc.
102
04 210
…. - 202 05 808
808 06 510
not this
In MDR 07 211
Ctrl 123
102 100 08 902
304 ….
…. IR ALU 09 000
808 102 304 10 304
11 102
55 56
06
05
PC 06 PC 06
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
-202 05 808 -202 05 808
808 06 510 510 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
808 102 304 10 304 510 102 304 10 304
11 102 11 102
57 58
07
PC 07 PC 07
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
304 05 808 304 05 808
304 06 510 211 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
510 102 304 10 304 211 102 304 10 304
11 102 11 102
59 60
10
Instruction Execution ... 102 Instruction Fetch ... 102
MAR MAR
00 901 00 901
01 310 01 310
08
11
PC 08 PC 08
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
202 05 808 202 05 808
102 06 510 902 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
211 304 102 10 304 902 304 102 10 304
11 102 11 102
61 62
09
PC 09 PC 09
02 901 02 901
+1 03 311 +1 03 311
Out Acc. Out Acc.
04 210 04 210
202 202
202 05 808 202 05 808
…. 902 06 510 …. 000 06 510
In MDR 07 211 In MDR 07 211
Ctrl 123 Ctrl 123
100 08 902 100 08 902
…. 09 000 …. 09 000
IR ALU IR ALU
902 304 102 10 304 000 304 102 10 304
11 102 11 102
63 64
PC 09
02 901
+1 03 311
Out Acc. 04 210
202 202 05 808
…. 000 06 510
In MDR 07 211
Ctrl 123
100 08 902
…. 09 000
IR ALU
000 304 102 10 102
11 304
65
11