98
MIPS Datapath CMSC 301 Prof Szajda

MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

MIPS Datapath

CMSC 301Prof Szajda

Page 2: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Goal

•  Build an architecture to support the following instructionsw Arithmetic: add, sub, addi, sltw Memory references: lw, sww Branches: j, beq

Page 3: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Process

1)  Design basic framework that is needed by all instructions

2)  Build a computer for each operation individually

3)  Add MUXs to choose between different operations

4)  Add control signals to control the MUXs

Page 4: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

MIPS Steps

•  Get an instruction from memory using the Program Counter (PC)

•  Read one or two registers each instructionw One register: addi, lww  Two registers: add, sub, slt, sw, beq

•  All instructions use ALU after reading regs•  Some instructions also access Memory•  Write result to Register file

Page 5: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get instruction

from memory

Framework

Page 6: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read from

register file

Get instruction

from memory

Framework

Page 7: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read from

register file

Use ALU Get instruction

from memory

Framework

Page 8: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read from

register file

Use ALU Get instruction

from memory

Access memory

Framework

Page 9: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read from

register file

Use ALU Get instruction

from memory

Access memory

Write register file

Framework

Page 10: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Where do we store instructions?

Page 11: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Address Data

Where do we store instructions?

Memory

Page 12: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Address Data

How do we know at what address to fetch instruction?

Page 13: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Program Counter (PC)

Data

How do we know at what address to fetch instruction?

Program Counter

Page 14: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Program Counter (PC)

Data

What do we end up with?

Page 15: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Program Counter (PC)

Instruction

What do we end up with?

Instruction

Page 16: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Program Counter (PC)

Instruction

What happens to the PC each instruction?

Page 17: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Get Instruction

Instruction Memory

Program Counter (PC)

Instruction

What happens to the PC each instruction?

Increment by 4B

4

Page 18: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read from

register file

Use ALU Get instruction

from memory

Write register file

“Add” Instruction

Page 19: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read from

register file

Use ALU

Write register file

Read Addr Out Data

Instruction Memory

PC

Inst

4

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

“Add” Instruction

Page 20: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Use ALU

“Add” Instruction

Write register file

Read Addr Out Data

Instruction Memory

PC

Inst

4

Register File

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5 How many

registers do we need to read?

Page 21: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Use ALU

“Add” Instruction

Write register file

Read Addr Out Data

Instruction Memory

PC

Inst

4

Register File

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5 How many

registers do we need to read?

2

Page 22: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Use ALU

“Add” Instruction

Write register file

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

What part of instruction tells us the

register number?

Page 23: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Use ALU

“Add” Instruction

Write register file

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

What part of instruction tells us the

register number? rs & rt

Page 24: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Add” Instruction

op/fun rs rt rd imm

Write register file

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

Page 25: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Add” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destdata

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

How do we know which register to

write?

Page 26: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Add” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

How do we know which register to

write? rd

Page 27: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Add” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 2 0 32 # $2 <- $3 + $5

Page 28: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

What happens if instruction reads and writes same register?

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 3 0 32 # $3 <- $3 + $5

Page 29: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

What happens if instruction reads and writes same register?

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt rd shamt funct # meaning add 3 5 3 0 32 # $3 <- $3 + $5

What would happen if we allowed write to occur at any time?Clock is dependent on longest path (lw)Quick operations may loop twice through machine, getting incorrect result.

Page 30: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Reading/Write Registers

•  When does register get written?w At the end of the clock cyclew Edge-triggered circuits

Page 31: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6 What

registers do we read?

Page 32: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6 What

registers do we read?

rs

Page 33: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6 Where do

we get the second input?

Page 34: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 bits

32 bits

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6 Where do we

get the second input?

imm (16 bits)

Page 35: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Sign Extension

•  How do we go from 16-bit number to 32-bit number?

•  How about 4-bit to 8-bit.w 0111 = 7 = 00000111w 1110 = -2 = 11111110

•  Take the top bit and copy it to all the other bits

Page 36: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6 Sign extend

immediate value

Page 37: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6

How do we know which register to

write?

Page 38: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“Addi” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

Operation rs rt imm # meaning addi $5,$3,6 3 5 6 # $5 <- $3 + 6

How do we know which register to

write? rt

Page 39: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them Together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

Page 40: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them Together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

Two wires to the same input

Page 41: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them Together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

Two wires to the same input Add MUXs

Page 42: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them Together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

What determines

which to take?

Page 43: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them Together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

16 32 Sign Ext

What determines

which to take? Op/Func code

Control Unit

RegDest

ALUSrc

ALUOp

Page 44: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

Page 45: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

How many source regs? What part of instruction?

Page 46: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

How many source regs? 1 What part of instruction? rs

Page 47: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

Where do we get the second input?

Page 48: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

16 32 Sign Ext

Where do we get the second input? Sign extended imm

Page 49: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

16 32 Sign Ext

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

What do we do with the ALU output?

Page 50: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

16 32 Sign Ext

What do we do with the ALU output? Memory Address

Page 51: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Page 52: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Where do we write the result?

Page 53: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Load Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning lw $5,8($3) 3 5 8 # $5 <- M[$3 + 8]

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Where do we write the result?

rt

Page 54: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Page 55: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

Address calculation identical to load word

32 Sign Ext

16

Page 56: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Is $5 read or written?

Which register?

Page 57: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Is $5 read or written? read

Which register?

Page 58: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Is $5 read or written? read

Which register? rt

Page 59: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

What do we do with the value?

Page 60: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

What do we do with the value?

In Data for memory

Page 61: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

What do we do with OutData?

Page 62: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Store Operation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning sw $5,8($3) 3 5 8 # M[$3 + 8] <- $5

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

What do we do with OutData?

Nothing.

Page 63: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Control Unit

ALUOp

Page 64: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Control Unit

ALUOp

What do we NOT want it to do for a

store?

Page 65: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Control Unit

ALUOp

What do we NOT want it to do for a store? Write to

destreg

RegWrite

Page 66: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Control Unit

ALUOp

Do we want it to read or write?

RegWrite

Page 67: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Putting them together

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

Control Unit

ALUOp

Do we want it to read or write? Depends on

opcode

RegWrite

MemRd

MemWr

Page 68: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Page 69: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Page 70: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

What operation?

Page 71: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

What operation? Subtraction,

compared with 0

Zero?

Page 72: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

How do we go anywhere?

Zero?

Page 73: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

How do we go anywhere?

Change the PC

Zero?

Page 74: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Where do we want to go?

Zero?

Page 75: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Where do we want to go? Advance

imm instructions

Zero?

32 Sign Ext

16

Page 76: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Where do we want to go? Advance

imm instructions

Zero?

32 Sign Ext

16 But the PC is in

bytes.

Page 77: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Zero?

32 Sign Ext

16

<< 2

But the PC is in bytes. PC = (PC + 4)+ Imm<<2

Where do we want to go? Advance imm

instructions

Page 78: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Zero?

32 Sign Ext

16

<< 2

How do we use our Zero bit?

Page 79: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“beq” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation rs rt imm # meaning beq $3,$5,lp 3 5 6 # if ($3 == $5) goto lp

Zero?

32 Sign Ext

16

<< 2

How do we use our Zero bit?

Choose between PC+4 and PC+4+

(Imm<<2)

Page 80: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

“j” Instruction

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation Target address # meaning j loop 0x0174837 # goto loop

Where do we go?

Page 81: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation Target address # meaning j loop 0x0174837 # goto loop

Where do we go? To this absolute

address

“j” Instruction

Page 82: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation Target address # meaning j loop 0x0174837 # goto loop

Where do we go? To this absolute

address But this is only

______ bits, when the PC is _____

bits.

“j” Instruction

Page 83: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation Target address # meaning j loop 0x0174837 # goto loop

Where do we go? To this absolute

address But this is only 26 bits, when the PC is 32 bits.

“j” Instruction

Page 84: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation Target address # meaning j loop 0x0174837 # goto loop

Where do we go? To this absolute

address But this is only 26 bits, when the PC is 32 bits. Shift left, Concatenate

PC’s upper bits

“j” Instruction

Page 85: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Operation Target address # meaning j loop 0x0174837 # goto loop

But this is only 26 bits, when the PC is 32 bits. Shift left, Concatenate

current PC’s upper bits

“j” Instruction

4 bits

26 bits

<< 2

28 bits

Page 86: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

The Whole Shebang

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

Page 87: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Control Unit

•  Set of control line values cause appropriate actions to be taken at each step

•  Finite state machine determines what needs to be done at each stepw  Fetchw Decodew  Executew Memoryw Writeback

ACTIONS DEPEND ON

OPCODE

Page 88: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,
Page 89: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Single Cycle Latency

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

Page 90: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Time Diagram

Page 91: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Cycle Time

•  Not all instructions must go through all stepsw add doesn’t need to go to memory

•  Single long clock cycle makes add take as long as load

•  Can we change this?w Break single instruction execution into

small execution steps

Page 92: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Five Cycle Implementation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

Page 93: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Five Cycle Implementation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

FETCH

Page 94: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Five Cycle Implementation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

DECODE

Page 95: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Five Cycle Implementation

EXECUTE

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

Page 96: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Five Cycle Implementation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

MEMORY

Page 97: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

Five Cycle Implementation

Read Addr Out Data

Instruction Memory

PC

Inst

4

src1 src1data

src2 src2data Register File

destreg

destdata

op/fun rs rt rd imm

Addr Out Data

Data Memory

In Data

32 Sign Ext

16

<< 2

<< 2

WRITEBACK

Page 98: MIPS Datapath - University of RichmondMIPS Steps • Get an instruction from memory using the Program Counter (PC) • Read one or two registers each instruction! One register: addi,

How Many Cycles For:

•  add•  sw•  lw•  blt•  j