Professional Documents
Culture Documents
L07 CPU Design
L07 CPU Design
CPU Design
Sohaib Majzoub
Computer! Keyboard,
Mouse!
Processor! Memory! Devices!
Disk
(passive)! Input! (where !
Control! ! programs, !
(where !
programs, ! Output! data live
data live ! when not
Datapath! when! running)!
running)! Display,
Printer!
3
The CPU
• Processor (CPU): the active part of the
computer, which does all the work (data
manipulation and decision-making)
• Datapath: portion of the processor which
contains hardware necessary to perform
operations required by the processor (the
muscles)
• Control: portion of the processor (also in
hardware) which tells the datapath what
needs to be done (the brain)
Stages of the Datapath : Overview
4
• Stage 3: ALU
– the real work of most instructions is done
here: arithmetic (+, -, *, /), shifting, logic
(&, |), comparisons (slt)
– what about loads and stores?
• lw $t0, 40($t1)
• the address we are accessing in memory =
the value in $t1 PLUS the value 40
• so we do this addition in this stage
8
registers!
instruction! rd!
memory!
PC!
memory!
rs!
Data!
ALU
rt!
+4! imm!
!
1. Instruction! 2. Decode/! 5. Reg.!
3. Execute! 4. Memory!
Fetch! Register! Write!
Read!
11
reg[1]!
registers!
3!
instruction!
reg[1]+reg[2]!
memory!
PC!
memory!
1!
Data!
ALU
2! reg[2]!
imm!
+4!
add r3, r1, r2!
13
• slti $r3,$r1,17
–Stage 1: fetch this instruction, inc. PC
–Stage 2: decode to find it’s an slti, then read
register $r1
–Stage 3: compare value retrieved in Stage 2 with
the immediate 17
–Stage 4: idle
–Stage 5: write the result of Stage 3 in register $r3
14
reg[1]!
registers!
x!
instruction! reg[1]<17?!
memory!
PC!
memory!
1!
Data!
ALU
3!
imm! 17!
+4!
slti r3, r1, 17!
15
• sw $r3, 17($r1)
– Stage 1: fetch this instruction, inc. PC
– Stage 2: decode to find it’s a sw, then read
registers $r1 and $r3
– Stage 3: add 17 to value in register $r1
(retrieved in Stage 2)
– Stage 4: write value in register $r3
(retrieved in Stage 2) into memory address
computed in Stage 3
– Stage 5: idle (nothing to write into a register)
PC!
+4!
instruction!
memory!
1!
x!
3!
SW r3, 17(r1)!
imm!
registers!
17!
reg[1]!
reg[3]!
ALU
Example: sw Instruction
Data!
reg[1]+17!
MEM[r1+17]<=r3! memory!
16
17
• lw $r3, 17($r1)
– Stage 1: fetch this instruction, inc. PC
– Stage 2: decode to find it’s a lw, then read
register $r1
– Stage 3: add 17 to value in register $r1
(retrieved in Stage 2)
– Stage 4: read value from memory address
compute in Stage 3
– Stage 5: write value found in Stage 4 into
register $r3
PC!
+4!
instruction!
memory!
1!
x!
3!
registers!
17!
reg[1]!
ALU
Example: lw Instruction
Data!
reg[1]+17!
memory!
MEM[r1+17]!
19
20
Datapath Summary
• The datapath based on data transfers required
to perform instructions
• A controller causes the right transfers to happen
registers!
rd!
instruction!
memory!
PC!
memory!
rs!
Data!
ALU
rt!
+4! imm!
opcode, funct!
Controller!
21
!
1. Instruction! 2. Decode/! 5. Reg.!
3. Execute! 4. Memory!
Fetch! Register! Write!
Read!
24