Chapter 3 Lecture 1 Central Processing Unit
Chapter 3 Lecture 1 Central Processing Unit
Stack Organization
Instruction Formats
Addressing Modes
● Stack Architecture
2 / 44
1. Single Accumulator
Architecture
T0: AR PC (S S S =010, T0=1)
0 1 2
4 / 44
Microprogrammed Control unit
Control Memory
● Contains sequences of microoperations, and stored in Read-only
memory (ROM).
Control signals
● Group of bits used to select paths in multiplexers, decoders, arithmetic
logic units
Control word
● There are 14 binary selection inputs in the unit, and their combined
value specifies the control word.
● It consists of four fields, SELA(3bits)- source A, SELB(3bits)-source
B, SELD(3bits) – destination and OPR(5bits) – ALU operation
selector.
5
OPERATION OF CONTROL UNIT
The control unit directs the information flow through ALU by:
- Selecting various Components in the system
- Selecting the Function of ALU
[1] MUX A selector (SELA): BUS A R2
Example: R1 <- R2 + R3 [2] MUX B selector (SELB): BUS B R3
[3] ALU operation selector (OPR): ALU to ADD
[4] Decoder destination selector (SELD): R1 Out
Bus
3 3 3 5
Control Word SELA SELB SELD OPR
Binary
Code SELA SELB SELD
000 Input Input None
001 R1 R1 R1
Encoding of register selection fields 010 R2 R2 R2
011 R3 R3 R3
100 R4 R4 R4
101 R5 R5 R5
110 R6 R6 R6
111 R7 R7 R7
6
ALU CONTROL
OPR
Encoding of ALU operations Select Operation Symbol
00000 Transfer A TSFA
00001 Increment A INCA
00010 ADD A + B ADD
00101 Subtract A - B SUB
00110 Decrement A DECA
01000 AND A and B AND
01010 OR A and B OR
01100 XOR A and B XOR
01110 Complement A COMA
10000 Shift right A SHRA
11000 Shift left A SHLA
Examples of ALU Microoperations
Symbolic Designation
Microoperation SELA SELB SELD OPR Control Word
R1 R2 - R3 R2 R3 R1 SUB 010 011 001 00101
R4 R4 R5 R4 R5 R4 OR 100 101 100 01010
R6 R6 + 1 R6 - R6 INCA 110 000 110 00001
R7 R1 R1 - R7 TSFA 001 000 111 00000
Output R2 R2 - None TSFA 010 000 000 00000
Output Input Input - None TSFA 000 000 000 00000
R4 shl R4 R4 - R4 SHLA 100 000 100 11000
R5 0 R5 R5 R5 XOR 101 101 101 01100
7
General Register Organization
Input
OPR Operation R1
00000 Transfer A R2
R3
00001 Increment A R4
00010 Add A + B R5
00101 Subtract A − B R6
00110 Decrement A R7
9 / 44
10 / 44
Stack Organization
A stack is a storage device that stores information in such a
manner that the item stored last is the first item retrieved-LIFO.
The stack in digital computers is essentially a memory unit in
the cpu.
A register that holds the address for the stack is called stack
pointer, holds top of stack address.
There are two operations in stack data insertion – push and data
deletion – pop.
11 / 44
Stack Organization
LIFO Current
Last In First Out Top of Stack
TOS 0
1
2
3
4
5
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
12 / 44
Stack Organization
PUSH Current 1 6 9 0
SP ← SP – 1 Top of Stack
TOS 0
M[SP] ← DR 1
2
If (SP = 0) then (FULL ← 1)
3
EMPTY ← 0 4
5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
13 / 44
Stack Organization
POP Current
DR ← M[SP] Top of Stack
TOS 0
SP ← SP + 1 1
2
If (SP = 11) then (EMPTY ← 1)
3
FULL ← 0 4
5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
14 / 44
Stack Organization
Memory Stack
● PUSH PC 0
1
SP ← SP – 1 2
M[SP] ← DR
AR 100
● POP
101
DR ← M[SP] 102
SP ← SP + 1
200
SP 201
202
15 / 44
Exercise - 2
Let SP = 000000 in the stack of figure below. How many items
are there in the if:
A. FULL = 1 and EMTY = 0?
B. FULL = 0 and EMTY = 1?
16 / 44
8.5
(a) Stack full with 64 items.
(b) stack empty
17 / 44
Classifying Computer or Instruction Set
Architectures
The type of internal storage in the CPU is the most basic
differentiation. The major choices are a stack, an
accumulator, or a set of registers.
– Stack Computer Architecture
– AC Computer Architecture
– General Purpose Register Computer Architecture
General Other
Stack
ALU
ALU
AC Registers ALU
Purpose Registers
Registers
memory memory
acc = acc + mem[C] R1 = R1 + mem[C] R3 = R1 + R2
Instruction Formats – number of addresses
The number of address fields in the instruction format
depends on the internal organization of CPU
♦ Three-Address Instructions
– ADD R1, R2, R3 R1 ← R2 + R3
♦ Two-Address Instructions
– ADD R1, R2 R1 ← R1 + R2
♦ One-Address Instructions
– ADD M AC ← AC + M[AR]
♦ Zero-Address Instructions
– ADD TOS ← TOS + (TOS – 1)
22 / 44
Instruction Formats
23 / 44
Instruction Formats
26 / 44
Addressing Modes
Immediate
● The use of a constant in “MOV R1, 5”, i.e. R1 ← 5
Register
● Indicate which register holds the operand
27 / 44
Addressing Modes
Register Indirect
● Indicate the register that holds the number of the
register that holds the operand
R1
MOV R1, (R2)
Autoincrement / Autodecrement R2 = 3
Direct Address
● Use the given address to access a memory location
28 / 44
Addressing Modes
Indirect Address
● Indicate the memory location that holds the address of
the memory location that holds the data
AR = 101
100
101 0 1 0 4
102
103
104 1 1 0 A
29 / 44
Addressing Modes
Relative Address
● EA = PC + Relative Addr 0
1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive 103
or Negative 104
(2’s Complement)
30 / 44
Addressing Modes
Indexed
● EA = Index Register + Relative Addr
Useful with XR = 2
“Autoincrement” or
“Autodecrement”
+
100
AR = 100
101
Could be Positive
or Negative 102 1 1 0 A
(2’s Complement) 103
104
31 / 44
Addressing Modes
Base Register
● EA = Base Register + Relative Addr
Could be Positive AR = 2
or Negative
(2’s Complement)
+
100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points 103 0 1 0 7
to the beginning 104 0 0 5 9
of an array
32 / 44
Types of Instructions
Data Transfer Instructions
Name Mnemonic
Data value is
Load LD not modified
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
34 / 44
Data Manipulation Instructions
Name Mnemonic
Arithmetic Increment INC
Decrement DEC
Logical & Bit Manipulation Add ADD
Subtract SUB
Shift Multiply MUL
Divide DIV
Add with carry ADDC
Subtract with borrow SUBB
Name Mnemonic
Negate NEG
Clear CLR
Complement COM Name Mnemonic
AND AND Logical shift right SHR
OR OR Logical shift left SHL
Exclusive-OR XOR Arithmetic shift right SHRA
Clear carry CLRC Arithmetic shift left SHLA
Set carry SETC Rotate right ROR
Complement carry COMC Rotate left ROL
Enable interrupt EI Rotate right through carry RORC
Disable interrupt DI Rotate left through carry ROLC
35 / 44
CISC
Complex Instruction Set Computer
● Large number of instructions with a complicated ALU
● Some instructions perform specialized tasks and are
used infrequently
● Large variety of addressing modes
● Variable length instruction formats
● Instructions can manipulate operands in memory
36 / 44
RISC
Reduced Instruction Set Computer
● Relatively few instructions, hence simple ALU
● Relatively few addressing modes
● Memory access limited to “load” and “store”
● All operations done within “registers” of the CPU
● Fixed-length and easily decoded instruction format
● Single-cycle instruction execution
● Hardwired control unit
37 / 44