Processor Organization & Instruction Cycle
Processor Organization & Instruction Cycle
Processor Organization & Instruction Cycle
1
Instruction Sets Review
3
Processor Organization
4
Processor Organizationcntd
CPU contains:
Registers
Internal processor memory
ALU
performs arithmetic and logic operations (processes data)
Operates only on data in registers
ALU with its inputs and outputs is termed as a data path
Control Unit
Decodes instructions, generates control signals to control
the processor
Internal Bus
Interconnects CPU parts
5
Register Organization
Types of registers
User-visible registers
They can be directly accessed (read or written to) by
programmers (instructions)
Used to minimize memory reference
Control registers
Used by control unit to control operation of the processor
Status (flag) registers
Indicate the current state (status) of the processor
8
Status registers
9
Instruction Cycle
e.g. MOV R1, [200] 100 MOV R1, [200]
Memory
200 10
10
Instruction Cycle with Interrupt
Process Interrupt
Fetch Instruction
Store PC in
Interpret (decode)
memory (stack)
Instruction
Load address of
[Fetch Data]
ISR on PC
Pipelining
Pipelining hazards
Resource hazards
Data hazards
Control hazards
12
Review
= .
CPI: Average clock cycle per instruction
14
Pipelining
Clk
Instruction 1 Fetch Decode Execute
Instruction 2 Fetch Decode Execute
Instruction 3
Clk
Instruction 1 Fetch Decode Execute
Instruction 2 Fetch Decode Execute
Instruction 3 Fetch Decode Execute
PC FI/DI DI/EI
R R
e e
g g
Fetch i Decode i Execute
s s
(FI) t
(DI) t
(EI)
e e
r r
s s
17
More stages
18
More stagescntd
Assume:
All instructions require all the five stages
Equal duration for each stage
Time
I1 FI DI FO EI WO
I2 FI DI FO EI WO
I3 FI DI FO EI WO
Speed up factor ( ) = =
, + 1
22
Pipeline Hazards
Pipeline hazards:
Resource (Structural) hazards
Data hazards
Control hazards
23
Resource Hazards
Address
Instructions I1 FI DI FO EI WO
CPU I2 FI DI FO EI WO
Data Data
I3 FI DI FO EI WO
Therefore the fetch instruction stage of the pipeline must stall (be
idle) for one cycle (one more clock cycle required to execute the 3
instructions)
Time
1 2 3 4 5 6 7 8
I1 FI DI FO EI WO Assume all other
I2 FI DI FO EI WO operands are in
registers
I3 Idle FI DI FO EI WO
25
Data Hazards
26
Data Hazardscntd
The hazard occurs if read takes place before the write operation is
complete
Other types of data hazards:
Write after read (WAR)
Write after write (WAW)
Approaches for handling data hazards:
Avoid hazard
Detect and stall
Detect and forward
27
Data Hazardscntd
28
Data Hazardscntd
Avoid hazard
Make sure there are no hazards in the code
Put no operation instructions between dependent instructions
(programmer or compiler)
ADD R1,R2
NOP (no operation)
ADD R3,R1
Detect and stall (wait until the write operation is over)
Time
1 2 3 4 5 6 7
ADD R1,R2 FI DI FO EI WO
(R1=0) (R1=1)
ADD R3,R1 FI DI idle idle FO EI
(R1=1)
FI DI FO
29
Control Hazards
30
Control Hazardscntd