Professional Documents
Culture Documents
• Introduction
• Stack Organization
• Instruction Formats
• Addressing Modes
• Program Control
1
Central Processing Unit Introduction
Transfer Components
Bus
Control Components
Control Unit
Register
Set ALU
Control Unit
2
Central Processing Unit General Register Organization
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA{ MUX MUX } SELB
3x8 A bus B bus
decoder
SELD
OPR ALU
Output
Example: R1 ← R2 + R3
[1] MUX A selector (SELA): BUS A ← R2
[2] MUX B selector (SELB): BUS B ← R3
[3] ALU operation selector (OPR): ADD
[4] Decoder destination selector (SELD): R1 ← Output Bus
3
Central Processing Unit General Register Organization
CONTROL WORD
Clock Input
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA{ MUX MUX } SELB
3x8 A bus B bus
decoder
SELD
OPR ALU
Output
3 3 3 5
Control Word SELA SELB SELD OPR
4
Central Processing Unit Control
CONTROL WORD
3 3 3 5
Control Word SELA SELB SELD OPR
Binary OPR
Code SELA SELB SELD Select Operation Symbol
000 Input Input None 00000 Transfer A TSFA
001 R1 R1 R1 00001 Increment A INCA
010 R2 R2 R2 00010 ADD A + B ADD
011 R3 R3 R3 00101 Subtract A - B SUB
100 R4 R4 R4 00110 Decrement A DECA
101 R5 R5 R5 01000 AND A and B AND
110 R6 R6 R6 01010 OR A and B OR
111 R7 R7 R7
01100 XOR A and B XOR
01110 Complement A COMA
10000 Shift right A SHRA
11000 Shift left A SHLA
5
Central Processing Unit Control
EXAMPLES OF MICROOPERATIONS
Symbolic Designation
Microoperation SELA SELB SELD OPR Control Word
6
Central Processing Unit Stack Organization
FULL EMPTY
Stack pointer 4
SP C 3
B 2
A 1
Push, Pop operations 0
DR
/* Initially, SP = 0, EMPTY = 1, FULL = 0 */
PUSH POP
SP ← SP + 1 DR ← M[SP]
M[SP] ← DR SP ← SP – 1
If (SP = 0) then (FULL ← 1) If (SP = 0) then (EMPTY ← 1)
EMPTY ← 0 FULL ← 0
7
Central Processing Unit Stack Organization
3000
stack
3997
SP 3998
3999
4000
- A portion of memory is used as a stack 4001
with a processor register as a stack pointer DR
- PUSH: SP ← SP - 1
M[SP] ← DR
- POP: DR ← M[SP]
SP ← SP + 1
(3 * 4) + (5 * 6) ⇒ 34*56*+
6
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
9
Central Processing Unit Instruction Format
INSTRUCTION FORMAT
Instruction Fields
OP-code field - specifies the operation to be performed
Address field - designates memory address(es) or a processor register(s)
Mode field - specifies the way the operand or the
effective address is determined
Three-Address Instructions
Program to evaluate X = (A + B) * (C + D) :
ADD R1, A, B /* R1 ← M[A] + M[B] */
ADD R2, C, D /* R2 ← M[C] + M[D] */
MUL X, R1, R2 /* M[X] ← R1 * R2 */
Two-Address Instructions
Program to evaluate X = (A + B) * (C + D) :
11
Central Processing Unit Instruction Format
ADDRESSING MODES
Addressing Modes
13
Central Processing Unit Addressing Modes
Implied Mode
Opcode Mode
Immediate Mode
14
Central Processing Unit Addressing Modes
Opcode Mode R1
Register field
R1
Mem Address Operand
15
Central Processing Unit Addressing Modes
Opcode Mode R1
Memory
R1
Before memory access Address Operand
R1
After memory access Address + 1
16
Central Processing Unit Addressing Modes
Operand
100
100 Operand
17
Central Processing Unit Addressing Modes
+ Operand
PC
18
Central Processing Unit Addressing Modes
+ Operand
Index Register
19
Central Processing Unit Addressing Modes
+ Operand
Base Register
20
Central Processing Unit Addressing Modes
399 450
XR = 100
400 700
AC
500 800
600 900
22
Central Processing Unit Data Transfer and Manipulation
A B
Status Flag Circuit 8 8
c7
8-bit ALU C: carry
c8
F7 - F0 S: sign
V Z S C Z: zero
F7
V: overflow
Check for 8
zero output
F
24
Central Processing Unit Program Control
25
Central Processing Unit Program Control
A = 11110000 B = 00010100
A: 11110000
B’+1 : + 11101100
A–B: 11011100 C=1 S=1 V=0 Z=0
Unsigned numbers:
A = 240 B = 20 A – B = 220
A > B, A ≠ B (C = 1, Z = 0) Inst. : BHI, BHE, BNE
Signed numbers:
A = -16 B = +20 A – B = -36
A < B, A ≠ B (S = 1, V = 0, Z = 0) Inst. : BLT, BLE, BNE
26
Central Processing Unit Program Control
Subroutine Call
SP ← SP – 1 Decrement stack pointer
M[SP] ← PC Push PC onto stack
PC ← EA Transfer control to subroutine
Subroutine Return
PC ← M[SP] Pop stack and transfer to PC
SP ← SP + 1 Increment stack pointer
27
Central Processing Unit Program Control
PROGRAM INTERRUPT
Types of Interrupts:
28
Central Processing Unit Program Control
INTERRUPT PROCEDURE
29
Central Processing Unit
EXERCISES
5 3 6 18
Opcode Mode Register Address
32
30
Central Processing Unit
EXERCISES
Address Memory
300 Opcode Mode
31