pipeline
DESCRIPTION
Pipeline. Lavanderia – analogia com o pipelining. Pipeline de instruções no MIPS. Fetch da instrução Leitura dos registradores e decodificação Execução da operação ou cálculo de endereço Acesso ao operando na memória Escrita do resultado em um registrador. Exemplo. - PowerPoint PPT PresentationTRANSCRIPT
Ch6.a-21998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Lavanderia – analogia com o pipelining
Ch6.a-31998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipeline de instruções no MIPS
• Fetch da instrução
• Leitura dos registradores e decodificação
• Execução da operação ou cálculo de endereço
• Acesso ao operando na memória
• Escrita do resultado em um registrador
Ch6.a-41998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Exemplo
• Compare o tempo médio entre instruções da implementação em single-cycle (uma instrução por ciclo) com uma implementação com pipeline. Supor maior tempo de operação para acesso à memória = 2ns, operação da ULA = 2ns e acesso ao register file = 1ns. (Instrs lw, sw, add, sub, and, or slt e beq).
• Inicialmente suponha a execução de 3 instruções lw (tempo entre o início da 1ª instrução e o início da 4ª instrução)
Ch6.a-51998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Tempo total para as oito instruções calculado a partir do tempo de cada componente
Ch6.a-61998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Execução não-pipeline X pipeline
Instructionfetch
Reg ALUData
accessReg
8 nsInstruction
fetchReg ALU
Dataaccess
Reg
8 nsInstruction
fetch
8 ns
Time
lw $1, 100($0)
lw $2, 200($0)
lw $3, 300($0)
2 4 6 8 10 12 14 16 18
2 4 6 8 10 12 14
...
Programexecutionorder(in instructions)
Instructionfetch
Reg ALUData
accessReg
Time
lw $1, 100($0)
lw $2, 200($0)
lw $3, 300($0)
2 nsInstruction
fetchReg ALU
Dataaccess
Reg
2 nsInstruction
fetchReg ALU
Dataaccess
Reg
2 ns 2 ns 2 ns 2 ns 2 ns
Programexecutionorder(in instructions)
Ch6.a-71998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
OBS.:
• Sob condições ideais, com estágios balanceados, o speedup do pipeline é igual ao número de estágios do pipeline ( 5 estágios , 5 vezes mais rápido)
• Na realidade o tempo de execução de uma instrução é um pouco superior (overheads) speedup é menor que o número de estágios do pipeline
Suponha a execução de 1003 instruções
com pipeline 1000 X 2ns + 14 = 2014 (para cada instrução adiciono 2ns)
sem pipeline 1000 X 8ns + 24 = 8024
spedup = 8024 / 2014 = 3.98 ~~ 8 / 2
Desempenho do pipelineé devido ao aumento dothroughput.
Ch6.a-81998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Projeto de um conjunto de instruções para pipeline
O que torna a implementação mais fácil
– Instruções de mesmo tamanho
– Poucos formatos, com campos de registradores sempre dispostos no mesmo lugar (Simetria, no 2º estágio podemos ler registradores e decodificar ao mesmo tempo).
– Acesso à memória apenas com as instruções lw e sw.
– Operandos alinhados na memória: o dado pode ser transferido da memória para a CPU e CPU para a memória em um único estágio do pipeline.
Ch6.a-91998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Projeto de um conjunto de instruções para pipeline
O que torna a implementação mais dificil
– Hazard
• Hazard Estrural
• Hazard de Controle
• Hazard de Dados
Ch6.a-101998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipeline Hazards
• Hazard Estrutural
– O hardware não suporta uma combinação de instruções que queremos executar em um único período de clock
• Ex.: escrever e ler da memória em um mesmo ciclo
Ch6.a-111998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipeline Hazards
• Hazard de Controle
– Problemas devido à execução de instruções de desvio
• Ex.: Quando um branch é tomado, como tratar a(s) instruções que seguem (fisicamente) o branch no programa e que já estão no pipeline
Ch6.a-121998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelining stalling para instruções branch
Instructionfetch
Reg ALUData
accessReg
Time
beq $1, $2, 40
add $4, $5, $6
lw $3, 300($0)4 ns
Instructionfetch
Reg ALUData
accessReg
2ns
Instructionfetch
Reg ALUData
accessReg
2ns
2 4 6 8 10 12 14 16Programexecutionorder(in instructions)
Ch6.a-131998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Branch prediction: Tentar “adivinhar” qual dos caminhos do branch será tomado
Instructionfetch
Reg ALUData
accessReg
Time
beq $1, $2, 40
add $4, $5, $6
lw $3, 300($0)
Instructionfetch
Reg ALUData
accessReg
2 ns
Instructionfetch
Reg ALUData
accessReg
2 ns
Programexecutionorder(in instructions)
Instructionfetch
Reg ALUData
accessReg
Time
beq $1, $2, 40
add $4, $5 ,$6
or $7, $8, $9
Instructionfetch
Reg ALUData
accessReg
2 4 6 8 10 12 14
2 4 6 8 10 12 14
Instructionfetch
Reg ALUData
accessReg
2 ns
4 ns
bubble bubble bubble bubble bubble
Programexecutionorder(in instructions)
O branch não será tomado
Ch6.a-141998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipeline delayed branch
Instructionfetch
Reg ALUData
accessReg
Time
beq $1, $2, 40
add $4, $5, $6
lw $3, 300($0)
Instructionfetch
Reg ALUData
accessReg
2 ns
Instructionfetch
Reg ALUData
accessReg
2 ns
2 4 6 8 10 12 14
2 ns
(Delayed branch slot)
Programexecutionorder(in instructions)
Ch6.a-151998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Hazard de Dados
• Quando uma instrução necessita de um dado que ainda não foi calculado
– Ex.: add $s0,$t0,$t1
sub $t2,$s0,$t3
Soluções : Compilador (programador) gera código livre de data hazard (introduzindo, por ex., instruções nop no código; alterando a ordem das instruções; ...)
Stall; Forwarding ou bypassing
Ch6.a-161998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Hazard de Dados
add $s0, $t0, $t1
sub $t2, $s0, $t3
Programexecutionorder(in instructions)
IF ID WBEX
IF ID MEMEX
Time2 4 6 8 10
MEM
WBMEM
Ch6.a-171998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Hazard de Dados
Time2 4 6 8 10 12 14
lw $s0, 20($t1)
sub $t2, $s0, $t3
Programexecutionorder(in instructions)
IF ID WBMEMEX
IF ID WBMEMEX
bubble bubble bubble bubble bubble
Stall
Ch6.a-181998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Exemplo
• Encontre o hazard no código abaixo e resolva-o:
# $t1 tem o end. de v[k]lw $t0, 0($t1) # $t0 = v[k]lw $t2,4($t1) # $t2 = v[k+1]sw $t2, 0($t1) # v[k] = $t2sw $t0, 4($t1) # v[k+1] = $t0
Solução:# $t1 tem o end. de v[k]
lw $t0, 0($t1) # $t0 = v[k]lw $t2,4($t1) # $t2 = v[k+1]sw $t0, 4($t1) # v[k+1] = $t0sw $t2, 0($t1) # v[k] = $t2
Ch6.a-191998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipeline: Idéia Básica • 5 estágios: Fetch; Decodificação e leitura dos regs; execução ou cálculo
de end. ; acesso à memória; escrita no reg. destino
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Instruction
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
ReaddataAddress
Datamemory
1
ALUresult
Mux
ALUZero
IF: Instruction fetch ID: Instruction decode/register file read
EX: Execute/address calculation
MEM: Memory access WB: Write back
O que é necessário para tornar cada divisão em estágios?
Ch6.a-201998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instruções sendo executadas pelo datapath
IM Reg DM RegALU
IM Reg DM RegALU
CC 1 CC 2 CC 3 CC 4 CC 5 CC 6 CC 7
Time (in clock cycles)
lw $2, 200($0)
lw $3, 300($0)
Programexecutionorder(in instructions)
lw $1, 100($0) IM Reg DM RegALU
Ch6.a-211998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Datamemory
Address
Pode acontecer algum problema nesta solução se não existir dependência de dados?
A execução de qual instrução causa o problema?
Ch6.a-221998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Instruction fetch
lw
Address
Datamemory
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Instruction decode
lw
Address
Datamemory
Ch6.a-231998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Instruction fetch
lw
Address
Datamemory
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Instruction decode
lw
Address
Datamemory
Ch6.a-241998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Execution
lw
Address
D atamemory
Ch6.a-251998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Memory
lw
Address
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writedata
ReaddataData
memory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Write back
lw
Writeregister
Address
97108/Patterson Figure 06.15
Ch6.a-261998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Memory
lw
Address
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writedata
ReaddataData
memory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Write back
lw
Writeregister
Address
97108/Patterson Figure 06.15
Ch6.a-271998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Execution
sw
Address
Ch6.a-281998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Memory
sw
Address
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0
Address
Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Write back
sw
Ch6.a-291998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Pipelined Datapath
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Memory
sw
Address
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM
Mux
0
1
Add
PC
0
Address
Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX MEM/WB
Write back
sw
Ch6.a-301998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Datapath Correto
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0
Address
Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
Datamemory
1
ALUresult
Mux
ALUZero
ID/EX
Problema na execução da instrução load.Qual é o erro?
Ch6.a-311998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Datapath com os estágios usados para um instrução lw
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Address
Datamemory
Ch6.a-321998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Representações Gráfica do Pipeline
IM R e g D M R e g
IM R e g D M R e g
C C 1 C C 2 C C 3 C C 4 C C 5 C C 6
T im e (in c lo c k c y cle s )
lw $ 1 0 , 2 0 ( $ 1 )
P ro g ra me x e c u t io no rd e r( in in s tr u c tio n s )
s u b $ 1 1 , $ 2 , $ 3
A L U
A L U
Ajuda a responder perguntas como:Quantos ciclos são gasto para executar este código?O que a ALU está fazendo durante o ciclo 10?
Ajuda a entender os datapaths
Ch6.a-331998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Representações Gráfica do Pipeline
Programexecutionorder(in instructions)
Time ( in clock cycles)
CC 1 CC 2 CC 3 CC 4 CC 5 CC 6
Instructionfetch
Instructiondecode
Instructionfetch
Instructiondecode Execution Write back
Execution
Dataaccess
Dataaccess Write backlw $10, $20($1)
sub $11, $2, $3
Ch6.a-341998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Instruction decode
lw $10, 20($1)
Instruction fetch
sub $11, $2, $3
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Instruction fetch
lw $10, 20($1)
Address
Datamemory
Address
Datamemory
Clock 1
Clock 2
Ch6.a-351998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Instruction decode
lw $10, 20($1)
Instruction fetch
sub $11, $2, $3
Instructionmemory
Address
4
32
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Instruction fetch
lw $10, 20($1)
Address
Datamemory
Address
Datamemory
Clock 1
Clock 2
Ch6.a-361998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
4
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
3216Sign
extend
Writeregister
Writedata
Memory
lw $10, 20($1)
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Execution
sub $11, $2, $3
Instructionmemory
Address
4
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Execution
lw $10, 20($1)
Instruction decode
sub $11, $2, $3
3216Sign
extend
Address
Datamemory
Datamemory
Address
Clock 3
Clock 4
Ch6.a-371998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
4
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
3216Sign
extend
Writeregister
Writedata
Memory
lw $10, 20($1)
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Execution
sub $11, $2, $3
Instructionmemory
Address
4
0
Add Addresult
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEM MEM/WB
Mux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Writeregister
Writedata
Readdata
1
ALUresult
Mux
ALUZero
ID/EX
Execution
lw $10, 20($1)
Instruction decode
sub $11, $2, $3
3216Sign
extend
Address
Datamemory
Datamemory
Address
Clock 3
Clock 4
Ch6.a-381998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
4
32
0
Add Addresult
1
ALUresult
Zero
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEMID/EX MEM/WB
Write backMux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Mux
ALUReaddata
Writeregister
Writedata
lw $10, 20($1)
Instructionmemory
Address
4
32
0
Add Addresult
1
ALUresult
Zero
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEMID/EX MEM/WB
Write backMux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Mux
ALUReaddata
Writeregister
Writedata
sub $11, $2, $3
Memory
sub $11, $2, $3
Address
Datamemory
Address
Datamemory
Clock 6
Clock 5
Ch6.a-391998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
4
32
0
Add Addresult
1
ALUresult
Zero
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEMID/EX MEM/WB
Write backMux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Mux
ALUReaddata
Writeregister
Writedata
lw $10, 20($1)
Instructionmemory
Address
4
32
0
Add Addresult
1
ALUresult
Zero
Shiftleft 2
Inst
ruct
ion
IF/ID EX/MEMID/EX MEM/WB
Write backMux
0
1
Add
PC
0Writedata
Mux
1Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
16Sign
extend
Mux
ALUReaddata
Writeregister
Writedata
sub $11, $2, $3
Memory
sub $11, $2, $3
Address
Datamemory
Address
Datamemory
Clock 6
Clock 5
Ch6.a-401998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Controle do Pipeline
PC
Instructionmemory
Address
Inst
ruct
ion
Instruction[20– 16]
MemtoReg
ALUOp
Branch
RegDst
ALUSrc
4
16 32Instruction[15– 0]
0
0Registers
Writeregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Signextend
Mux
1Write
data
Read
data Mux
1
ALUcontrol
RegWrite
MemRead
Instruction[15– 11]
6
IF/ID ID/EX EX/MEM MEM/WB
MemWrite
Address
Datamemory
PCSrc
Zero
AddAdd
result
Shiftleft 2
ALUresult
ALUZero
Add
0
1
Mux
0
1
Mux
Ch6.a-411998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Controle do Pipeline
• 5 estágios. O que deve ser controlado em cada estágio?
– 10: Fetch da instrução e incremento do PC
– 20: Decodificação da instrução e Fetch dos registradores
– 30: Execução
– 40: Acesso à memória
– 50: Write back
Ch6.a-421998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Sinais de controle
Ch6.a-431998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Sinais de controle
Ch6.a-441998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Sinais de controle
Execution/Address Calculation stage
control linesMemory access stage
control lines
Write-back stage control
lines
InstructionReg Dst
ALU Op1
ALU Op0
ALU Src Branch
Mem Read
Mem Write
Reg write
Mem to Reg
R-format 1 1 0 0 0 0 0 1 0lw 0 0 0 1 0 1 0 1 1sw X 0 0 1 0 0 1 0 Xbeq X 0 1 0 1 0 0 0 X
Ch6.a-451998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Control
EX
M
WB
M
WB
WB
IF/ID ID/EX EX/MEM MEM/WB
Instruction
Ch6.a-461998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Datapath com Controle
PC
Instructionme mory
Inst
ruct
ion
Add
Instruction[20– 16]
Me
mto
Reg
ALUOp
Branch
RegDst
ALUSrc
4
16 32Instruction[15– 0]
0
0
Mux
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Signex tend
Mux1
ALUresult
Zero
Writedata
Readdata
Mux
1
ALUcontrol
Shiftleft 2R
eg
Writ
e
MemRead
Control
ALU
Instruction[15– 11]
6
EX
M
WB
M
WB
WBIF/ID
PCSrc
ID/EX
EX/MEM
MEM/ WB
Mux
0
1
Me
mW
rite
AddressData
me mory
Address
Ch6.a-471998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
Instructionmemory
Instruction[20– 16]
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
Instruction[15– 0]
0
Mux
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Signextend
Mux
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
EX
M
WB
M
WB
WBIn
stru
ctio
n
IF/ID EX/MEMID/EX
ID: before<1> EX: before<2> MEM: before<3> WB: before<4>
MEM/WB
IF: lw $10, 20($1)
000
00
0000
000
00
000
0
00
00
0
0
0
Mux
0
1
Add
PC
0
Datamemory
Address
Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
Mux
0
1
Add Addresult
Writeregister
Writedata
Mux
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Re
gWrit
e
ALU
M
WB
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: lw $10, 20($1) EX: before<1> MEM: before<2> WB: before<3>
MEM/WB
IF: sub $11, $2, $3
010
11
0001
000
00
000
0
00
00
0
0
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
lwControl
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
X
10
20
X
1
Instruction[20– 16]
Instruction[15– 0] Sign
extend
Instruction[15– 11]
20
$X
$1
10
X
Me
mW
rite
MemRead
Me
mW
rite
Datamemory
Address
Address
Address
Clock 2
Clock 1
1o ciclo
Ch6.a-481998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
Instructionmemory
Instruction[20– 16]
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
Instruction[15– 0]
0
Mux
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Signextend
Mux
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
EX
M
WB
M
WB
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: before<1> EX: before<2> MEM: before<3> WB: before<4>
MEM/WB
IF: lw $10, 20($1)
000
00
0000
000
00
000
0
00
00
0
0
0
Mux
0
1
Add
PC
0
Datamemory
Address
Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
Mux
0
1
Add Addresult
Writeregister
Writedata
Mux
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Re
gWrit
e
ALU
M
WB
WBIn
stru
ctio
n
IF/ID EX/MEMID/EX
ID: lw $10, 20($1) EX: before<1> MEM: before<2> WB: before<3>
MEM/WB
IF: sub $11, $2, $3
010
11
0001
000
00
000
0
00
00
0
0
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
lwControl
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
X
10
20
X
1
Instruction[20– 16]
Instruction[15– 0] Sign
extend
Instruction[15– 11]
20
$X
$1
10
X
Me
mW
rite
MemRead
Me
mW
rite
Datamemory
Address
Address
Address
Clock 2
Clock 12o ciclo
Ch6.a-491998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
Instruction[20– 16]
Mem
toR
eg
Branch
ALUSrc
4
Instruction[15– 0]
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
ALUresult
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
EX
M
WB
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: sub $11, $2, $3 EX: lw $10, . . . MEM: before<1> WB: before<2>
MEM/WB
IF: and $12, $4, $5
000
10
1100
010
11
000
1
00
00
0
0
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
Writeregister
Writedata 1
ALUresult
ALUcontrol
Shiftleft 2
Re
gWrit
e
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: and $12, $2, $3 EX: sub $11, . . . MEM: lw $10, . . . WB: before<1>
MEM/WB
IF: or $13, $6, $7
000
10
1100
000
10
101
0
11
10
0
0
0
Mux
0
1
Add
PC
0Writedata
Mux
1
andControl
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
12
X
X
5
4
Instruction[20– 16]
Instruction[15– 0]
Instruction[15– 11]
X
$5
$4
X
12
Me
mW
rite
MemRead
Me
mW
rite
sub
11
X
X
3
2
X
$3
$2
X
11
$1
20
10
Mux
0
Mux
1
ALUOp
RegDst
ALUcontrol
M
WB
$3
$2
11
Mux
Mux
ALUAddress Read
dataData
memory
10
WB
Zero
Zero
Signextend
Signextend
Datamemory
Address
Clock 3
Clock 4
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
3o ciclo
Ch6.a-501998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
Instruction[20– 16]
Mem
toR
eg
Branch
ALUSrc
4
Instruction[15– 0]
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
ALUresult
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
EX
M
WB
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: sub $11, $2, $3 EX: lw $10, . . . MEM: before<1> WB: before<2>
MEM/WB
IF: and $12, $4, $5
000
10
1100
010
11
000
1
00
00
0
0
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
Writeregister
Writedata 1
ALUresult
ALUcontrol
Shiftleft 2
Re
gWrit
e
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: and $12, $2, $3 EX: sub $11, . . . MEM: lw $10, . . . WB: before<1>
MEM/WB
IF: or $13, $6, $7
000
10
1100
000
10
101
0
11
10
0
0
0
Mux
0
1
Add
PC
0Writedata
Mux
1
andControl
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
12
X
X
5
4
Instruction[20– 16]
Instruction[15– 0]
Instruction[15– 11]
X
$5
$4
X
12
Me
mW
rite
MemRead
Me
mW
rite
sub
11
X
X
3
2
X
$3
$2
X
11
$1
20
10
Mux
0
Mux
1
ALUOp
RegDst
ALUcontrol
M
WB
$3
$2
11
Mux
Mux
ALUAddress Read
dataData
memory
10
WB
Zero
Zero
Signextend
Signextend
Datamemory
Address
Clock 3
Clock 4
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
4o ciclo
Ch6.a-511998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
Instruction[20– 16]
Branch
ALUSrc
4
Instruction[15– 0]
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
ALUresult
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
EX
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: or $13, $6, $7 EX: and $12, . . . MEM: sub $11, . . . WB: lw $10, . . .
MEM/WB
IF: add $14, $8, $9
000
10
1100
000
10
101
0
10
00
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
1
ALUresult
ALUcontrol
Shiftleft 2
Re
gWrit
e
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: add $14, $8, $9 EX: or $13, . . . MEM: and $12, . . . WB: sub $11, . . .
MEM/WB
IF: after<1>
000
10
1100
000
10
101
0
10
00
0
1
0
Mux
0
1
Add
PC
0Writedata
Mux
1
addControl
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
14
X
X
9
8
Instruction[20– 16]
Instruction[15– 0]
Instruction[15– 11]
X
$9
$8
X
14
Me
mW
rite
MemRead
Me
mW
rite
or
13
X
X
7
6
X
$7
$6
X
13
$4
Mux
0
Mux
1
ALUOp
RegDst
ALUcontrol
M
WB
$7
$6
13
Mux
Mux
ALUReaddata
12
WB
11 10
10$5
12
WB
Mem
toR
eg
1
1
11
11
Writeregister
Writedata
Zero
Zero
Datamemory
Address
Datamemory
Address
Signextend
Signextend
Clock 5
Clock 6
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
5o ciclo
Ch6.a-521998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
Instruction[20– 16]
Branch
ALUSrc
4
Instruction[15– 0]
0
1
Add Addresult
RegistersWriteregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2
ALUresult
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
EX
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: or $13, $6, $7 EX: and $12, . . . MEM: sub $11, . . . WB: lw $10, . . .
MEM/WB
IF: add $14, $8, $9
000
10
1100
000
10
101
0
10
00
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
1
ALUresult
ALUcontrol
Shiftleft 2
Re
gWrit
e
M
WBIn
stru
ctio
n
IF/ID EX/MEMID/EX
ID: add $14, $8, $9 EX: or $13, . . . MEM: and $12, . . . WB: sub $11, . . .
MEM/WB
IF: after<1>
000
10
1100
000
10
101
0
10
00
0
1
0
Mux
0
1
Add
PC
0Writedata
Mux
1
addControl
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
14
X
X
9
8
Instruction[20– 16]
Instruction[15– 0]
Instruction[15– 11]
X
$9
$8
X
14
Me
mW
rite
MemRead
Me
mW
rite
or
13
X
X
7
6
X
$7
$6
X
13
$4
Mux
0
Mux
1
ALUOp
RegDst
ALUcontrol
M
WB
$7
$6
13
Mux
Mux
ALUReaddata
12
WB
11 10
10$5
12
WB
Mem
toR
eg
1
1
11
11
Writeregister
Writedata
Zero
Zero
Datamemory
Address
Datamemory
Address
Signextend
Signextend
Clock 5
Clock 6
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
6o ciclo
Ch6.a-531998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
Instruction[20– 16]
Branch
ALUSrc
4
Instruction[15– 0]
0
1
Add Addresult
RegistersWriteregister
Writedata
ALUresult
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
Signextend
EX
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: after<1> EX: add $14, . . . MEM: or $13, . . . WB: and $12, . . .
MEM/WB
IF: after<2>
000
00
0000
000
10
101
0
10
00
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Re
gWrit
e
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: after<2> EX: after<1> MEM: add $14, . . . WB: or $13, . . .
MEM/WB
IF: after<3>
000
00
0000
000
00
000
0
10
00
0
1
0
Mux
0
1
Add
PC
0Writedata
Mux
1
Control
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Instruction[20– 16]
Instruction[15– 0] Sign
extend
Instruction[15– 11]
Me
mW
rite
MemRead
Me
mW
rite
$8
Mux
0
Mux
1
ALUOp
RegDst
ALUcontrol
M
WB
Mux
Mux
ALUReaddata
14
WB
13 12
12$9
14
WB
Mem
toR
eg
1
0
13
13
Writeregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2 Zero
Datamemory
Address
Datamemory
Address
Clock 7
Clock 8
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
7o ciclo
Ch6.a-541998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
Instructionmemory
Address
Instruction[20– 16]
Branch
ALUSrc
4
Instruction[15– 0]
0
1
Add Addresult
RegistersWriteregister
Writedata
ALUresult
Shiftleft 2
Re
gWrit
e
MemRead
Control
ALU
Instruction[15– 11]
Signextend
EX
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: after<1> EX: add $14, . . . MEM: or $13, . . . WB: and $12, . . .
MEM/WB
IF: after<2>
000
00
0000
000
10
101
0
10
00
0
Mux
0
1
Add
PC
0Writedata
Readdata
Mux
1
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Re
gWrit
e
M
WBIn
stru
ctio
n
IF/ID EX/MEMID/EX
ID: after<2> EX: after<1> MEM: add $14, . . . WB: or $13, . . .
MEM/WB
IF: after<3>
000
00
0000
000
00
000
0
10
00
0
1
0
Mux
0
1
Add
PC
0Writedata
Mux
1
Control
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Instruction[20– 16]
Instruction[15– 0] Sign
extend
Instruction[15– 11]
Me
mW
rite
MemRead
Me
mW
rite
$8
Mux
0
Mux
1
ALUOp
RegDst
ALUcontrol
M
WB
Mux
Mux
ALUReaddata
14
WB
13 12
12$9
14
WB
Mem
toR
eg
1
0
13
13
Writeregister
Writedata
Readdata 1
Readdata 2
Readregister 1
Readregister 2 Zero
Datamemory
Address
Datamemory
Address
Clock 7
Clock 8
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
8o ciclo
Ch6.a-551998 Morgan Kaufmann PublishersPaulo C. Centoducatte – MC542 - IC/Unicamp- 2004s2
WB
EX
M
Instructionmemory
Address
Mem
toR
eg
ALUOp
Branch
RegDst
ALUSrc
4
0
0
1
Add Addresult
1
ALUresult
Zero
ALUcontrol
Shiftleft 2
Reg
Writ
e
M
WB
Inst
ruct
ion
IF/ID EX/MEMID/EX
ID: after<3> EX: after<2> MEM: after<1> WB: add $14, . . .
MEM/WB
IF: after<4>
000
00
0000
000
00
000
0
00
00
0
1
0
Mux
0
1
Add
PC
0Writedata
Mux
1
Control
Registers
Readdata 1
Readdata 2
Readregister 1
Readregister 2
Instruction[20– 16]
Instruction[15– 0] Sign
extend
Instruction[15– 11]
MemRead
Mem
Wri
te
Mux
Mux
ALUReaddata
WB
14
14
Writeregister
Writedata
Datamemory
Address
Clock 9
lw $10, 20 ($1)sub $11, $2, $3and $12, $4, $5or $13, $6, $7add $14, $8, $9
9o ciclo