Processor Design The Language of Bits: Computer Organisation and Architecture
Processor Design The Language of Bits: Computer Organisation and Architecture
The
Processor
Language
Design
of Bits
PROPRIETARY MATERIAL. 2014 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed in any form or by any
means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their individual course preparation.
PowerPoint Slides are being provided only to authorized professors and instructors for use in preparing for classes using the affiliated textbook. No other use or distribution of this PowerPoint slide
is permitted. The PowerPoint slide may not be sold and may not be distributed or be used by any student or any other third party. No part of the slide may be reproduced, displayed or distributed in
any form or by any means, electronic or otherwise, without the prior written permission of McGraw Hill Education (India) Private Limited.
1
These slides are meant to be used along with the book: Computer
Organisation and Architecture, Smruti Ranjan Sarangi, McGrawHill 2015
Visit: http://www.cse.iitd.ernet.in/~srsarangi/archbooksoft.html
2
Outline
Overview of a Processor
Detailed Design of each Stage
The Control Unit
Microprogrammed Processor
Microassembly Language
The Microcontrol Unit
3
Processor Design
4
A Car Assembly Line
5
A Processor Divided Into Stages
6
Operand Fetch (OF) Stage
7
Execute (EX) Stage
The EX Stage
Contains an Arithmetic-Logical Unit (ALU)
This unit can perform all arithmetic
operations ( add, sub, mul, div, cmp, mod),
and logical operations (and, or, not)
Contains the branch unit for computing
the branch condition (beq, bgt)
Contains the flags register (updated by the
cmp instruction)
8
MA and RW Stages
MA (Memory Access) Stage
Interfaces with the memory system
Executes a load or a store
RW (Register Write) Stage
Writes to the register file
In the case of a call instruction, it writes the
return address to register, ra
9
Outline
Outline of a Processor
Detailed Design of each Stage
The Control Unit
Microprogrammed Processor
Microassembly Language
The Microcontrol Unit
10
Instruction Fetch (IF) Stage
Fetch unit
isBranchTaken
32 branchPC
32 1
32 32 inst
pc
1 1 - input 1
0 - input 0
0
Multiplexer
control signal
11
The Fetch unit
The pc register contains the program
counter (negative edge triggered)
We use the pc to access the instruction
memory
The multiplexer chooses between
pc + 4
branchTarget
It uses a control signal isBranchTaken
12
isBranchTaken
isBranchTaken is a control signal
It is generated by the EX unit
Conditions on isBranchTaken
Instruction Value of isBranchTaken
non-branch instruction 0
call 1
ret 1
b 1
branch taken 1
beq
branch not taken 0
branch taken 1
bgt
branch not taken 0
13
Data Path and Control Path
The data path consists of all the elements in
a processor that are dedicated to storing,
retrieving, and processing data such as
register files, memory, and the ALU.
14
Control Path
Control path
Interconnection network
15
Operand Fetch Unit
16
Instruction Formats
Format Definition
branch op (28-32) offset (1-27)
register op (28-32) I (27) rd (23-26) rs1 (19-22) rs2 (15-18)
immediate op (28-32) I (27) rd (23-26) rs1 (19-22) imm (1-18)
op opcode, offset branch offset, I immediate bit, rd destination register
rs1 source register 1, rs2 source register 2, imm immediate operand
17
Register File Read
isRet
ra(15)
1
op1
A read port 1 D
rs1
inst[19:22]
0
inst rd
inst[23:26] 1 op2
A read port 2 D
rs2
inst[15:18]
0
Register
A
address
isSt
file D data
19
Immediate and Branch Unit
imm 18 immx
calculate 32
inst[1:18]
immediate
pc
inst 27 shift by 2 bits 32 branchTarget
and extend sign
20
OF Unit
Fetch unit Operand fetch unit Execute
(opcode, I bit) 6 Control unit
inst[27:32] unit
imm 18
calculate 32 immx
imm. operands
inst[1:18] immediate
pc
isRet
ra(15)
1
op1
rs1 A read port 1 D
reg. operands
0
inst[19:22]
rd op2
inst[23:26] 1 D
A read port 2
rs2 A address
inst[15:18] 0 Register
isSt file D data
21
EX Stage Branch Unit
branchPC
branchTarget
from OF
0
op1
1
isRet
isBranchTaken
isUBranch
isBeq
flags.E
isBgt
flags.GT
flags
op1 A
ALU
aluResult
B (Arithmetic
immx
1 logic unit)
op2
0 s
isImmediate aluSignals
Choose between immx and op2 based on the value of the I bit
23
Inside the ALU
isLsl isLsr isAsr
B
Adder
isOr isNot isAnd
isMul
A
A Logical
B Multiplier unit B
isDiv isMod
isMov
A
B
B Divider Mov
aluResult
24
Disabling some Inputs
We do not want all the units of the ALU to be
active at the same time because of we want to
save power
The instruction will only use 1 unit
Power is dissipated when the inputs or outputs
make a transition (0 1, 1 0)
We shall avoid a transition by not letting the new
inputs to propagate to units that do not require
them
They will thus have the old inputs (no switching)
25
Use a Transmission Gate
S
26
EX Unit
Execute unit
branchPC
branchTarget
from OF
0
op1
1
isRet
isBranchTaken
isUBranch
isBeq
flags.E
isBgt
flags.GT
flags
op1 A
ALU
ALU and mem insts
aluResult
B (Arithmetic
immx
1 logic unit)
op2
0 s
isImmediate aluSignals
27
MA Unit
isLd isSt
32 op2
mdr
32 ldResult
Memory unit
32 aluResult
mar
mdr memory
data reg.
Data memory
mar memory
address reg.
28
RW Unit
register writeback unit
Register file
A
read port 1 isWb
D E ra(15)
1
write port A rd (inst[23:26])
A D 0
read port 2
D isCall
32 aluResult
00
32 ldResult result E enable
01
32
pc
10
A address
D data
isLd
4 isCall
29
1
pc + 4 0
pc Instruction
memory
Instruction Control
rd rs2 ra(15) rs1
unit
isRet
1 0 1 0
isSt
isWb
Register data
Immediate and
branch target file
reg
op2 op1
immx
01 1 0 isImmediate
isRet aluSignals
isBranchTaken
B A
Branch
ALU unit
mar mdr
isLd
pc
4 isLd
10 01 00 isCall
rd 0
ra(15) 1
data
30
Outline
Outline of a Processor
Detailed Design of each Stage
The Control Unit
Microprogrammed Processor
Microassembly Language
The Microcontrol Unit
31
The Ha rdwired Control Unit
opcode
inst[28:32]
Control control
I bit unit signals
inst[27]
32
Control Signals
33
Control Signals II
aluSignal
10 isAdd Instructions: add, ld, st
11 isSub Instruction: sub
12 isCmp Instruction: cmp
13 isMul Instruction: mul
14 isDiv Instruction: div
15 isMod Instruction: mod
16 isLsl Instruction: lsl
17 isLsr Instruction: lsr
18 isAsr Instruction: asr
19 isOr Instruction: or
20 isAnd Instruction: and
21 isNot Instruction: not
22 isMov Instruction: mov
34
Control signal Logic
opcode immediate bit
op5 op45 op3 op2 op1 I
35
Control Signal Logic - II
aluSignals
10 isAdd op5.op4.op3.op2.op1 + op5.op4.op3.op2
11 isSub op5.op4.op3.op2.op1
12 isCmp op5.op4.op3.op2.op1
13 isMul op5.op4.op3.op2.op1
14 isDiv op5.op4.op3.op2.op1
15 isMod op5.op4.op3.op2.op1
16 isLsl op5.op4.op3.op2.op1
17 isLsr op5.op4.op3.op2.op1
18 isAsr op5.op4.op3.op2.op1
19 isOr op5.op4.op3.op2.op1
20 isAnd op5.op4.op3.op2.op1
21 isNot op5.op4.op3.op2.op1
22 isMov op5.op4.op3.op2.op1
36
Outline
Outline of a Processor
Detailed Design of each Stage
The Control Unit
Microprogrammed Processor
Microassembly Language
The Microcontrol Unit
37
Microprogramming
Idea of microprogramming
Expose the elements in a processor to software
Implement instructions as dedicated software
routines
Why make the implementation of
instructions flexible ?
Dynamically change their behaviour
Fix bugs in implementations
Implement very complex instructions
38
Microprogrammed Data Path
Expose all the state elements to dedicated
system software firmware
Write dedicated routines in firmware for
implementing each instruction
Basic idea
1 SimpleRisc Instruction Several micro instructions
Execute each micro instruction
We require a microprogram counter, and
microinstruction memory
39
Fetch Unit
pc Instruction memory ir
Shared bus
The pc is used to access the instruction memory.
The contents of the instruction are saved in the
instruction register (ir)
40
Decode Unit
pc
ir
rs1 rs2 Immediate immx calc. branchTarget
I rd
unit offset
Shared bus
41
The Register File
Shared bus
args
regVal regData regSrc
Register
file
args
aluResult A B flags.E flags.GT
ALU flags
A, B ALU operands
args ALU operation type
aluResult ALU Result
43
Memory Unit
Shared bus
args
ldResult mar mdr
Data
memory
44
Microprogrammed Data Path
opcode
control
unit pc Instruction memory ir
Immediate immx calc. branchTarget
I rd rs1 rs2
unit offset
Shared bus
args
args
args
ldResult mar mdr aluResult A B flags.E flags.GT regVal regData regSrc
Data Register
ALU flags
memory file
45
Outline
Outline of a Processor
Detailed Design of each Stage
The Control Unit
Microprogrammed Processor
Microassembly Language
The Microcontrol Unit
46
Internal Registers
SerialNo. Register Size Function
(bits)
1 pc 32 program counter
2 ir 32 instruction register
3 I 1 immediate bit in the instruction
4 rd 4 destination register id
5 rs 1 4 id of the first source register
6 rs 2 4 id of the second source register
7 immx 32 immediate embedded in the
instruction (after processing
modifiers)
8 branchTarget 32 branch target, computed as the
sum of the PC and the offset
embedded in the instruction
9 regSrc 4 contains the id of the register
that needs to be accessed in the
register file
10 regData 32 contains the data to be written
into the register file
47
Internal Registers - II
48
Microinstructions
Basic Instructions
mloadIR Loads the instruction register (ir)
with the contents of the instruction.
mdecode Waits for 1 cycle. Meanwhile, all
the decode registers get populated
mswitch Loads the set of micro instructions
corresponding to a program instruction.
49
Move Microinstructions
mmov r1, r2 : r1 r2
mmov r1, r2, <args> : r1 r2, send the
value of args on the bus
mmovi r1, <imm> : r1 imm
50
Add and Branch Microinstructions
51
Summary of Microinstructions
6 madd reg1, imm, < args > reg1 reg1+imm, < args > is
optional
7 mbeq reg1, imm, < label > if (reg1 = imm) pc addr(label)
8 mb <label> pc addr(label)
52
Implementing Instructions in Microcode
54
The mov Instruction
mov instruction
55
The not Instruction
not instruction
56
The cmp Instruction
cmp instruction
57
The nop Instruction
mb .begin
58
The ld Instruction
ld instruction
59
The st Instruction
st instruction
60
beq and bgt Instructions
.branch: .branch:
mmov pc, branchTarget mmov pc, branchTarget
mb .begin mb .begin
61
call Instruction
call instruction
62
ret Instruction
ret instruction
63
Example
Change the call instruction to store the return address on the stack. The
preamble need not be shown.
Answer:
64
Outline
Outline of a Processor
Microprogrammed Processor
Microassembly Language
Microcontrol unit
imm
isMBranch
pc
Decode unit pc
Read bus
Write bus
Reg. file, ALU, Mem unit
Reg. file, ALU, Mem unit
Shared bus
66
Encoding an Instruction
Vertical Microprogramming (45 bit inst.)
3 bits type of instruction
5 bits source register
5 bits destination register
12 bits immediate
10 bit branch target in microcode memory
10 bit args value
3 bits (unit id)
7 bits operation code
67
Horizontal Microprogramming
Encoding
68
Vertical Microprogramming
mux switch
branchTarget
opcode
1
Microprogram Decode Execute
pc unit unit
memory control
signals
Data path
Shared bus
69
Horizontal Microprogramming
opcode
switch
mux
isMBranch
M1 branchTarget
1
Microprogram Execute
pc memory unit
control
signals
Data path
Shared bus
70
THE END
71