computer organization & programming chapter 6 single datapath cpu architecture

21
Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Upload: asher-riley

Post on 13-Dec-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Computer Organization & Programming

Chapter 6

Single DatapathCPU Architecture

Page 2: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

How to Design a Processor: step-by-step

1. Analyze instruction set => datapath requirements• the meaning of each instruction is given by the register

transfers• datapath must include storage element for ISA registers• datapath must support each register transfer

2. Select set of datapath components and establish clocking methodology

3. Assemble datapath meeting the requirements4. Analyze implementation of each instruction to

determine setting of control points that effects the register transfer.

5. Assemble the control logic

Page 3: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Overview of MIPS All MIPS instructions are 32 bits long. The three instruction formats:

• R-type

• I-type

• J-type

The different fields are:• op: operation of the instruction• rs, rt, rd: the source and destination register specifiers• shamt: shift amount• funct: selects the variant of the operation in the “op” field• address / immediate: address offset or immediate value

• target address: target address of the jump instruction

op rs rt rd shamt funct

061116212631

6 bits 6 bits5 bits5 bits5 bits5 bits

op rs rt immediate

016212631

6 bits 16 bits5 bits5 bits

op target address

02631

6 bits 26 bits

Page 4: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

MIPS Instructions

Page 5: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

MIPS Instructions

Page 6: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

MIPS Instructions

Page 7: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

MIPS Instructions

Page 8: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

MIPS Instructions

Page 9: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Assembly Language Example

Page 10: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

To summarize:

MIPS assembly language

Category Instruction Example Meaning Commentsadd add $s1, $s2, $s3 $s1 = $s2 + $s3 Three operands; data in registers

Arithmetic subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 Three operands; data in registers

add immediate addi $s1, $s2, 100 $s1 = $s2 + 100 Used to add constants

load word lw $s1, 100($s2) $s1 = Memory[$s2 + 100] Word from memory to register

store word sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Word from register to memory

Data transfer load byte lb $s1, 100($s2) $s1 = Memory[$s2 + 100] Byte from memory to register

store byte sb $s1, 100($s2) Memory[$s2 + 100] = $s1 Byte from register to memory

load upper immediate lui $s1, 100 $s1 = 100 * 216 Loads constant in upper 16 bits

branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to PC + 4 + 100

Equal test; PC-relative branch

Conditional

branch on not equal bne $s1, $s2, 25 if ($s1 != $s2) go to PC + 4 + 100

Not equal test; PC-relative

branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; else $s1 = 0

Compare less than; for beq, bne

set less than immediate

slti $s1, $s2, 100 if ($s2 < 100) $s1 = 1; else $s1 = 0

Compare less than constant

jump j 2500 go to 10000 Jump to target address

Uncondi- jump register jr $ra go to $ra For switch, procedure return

tional jump jump and link jal 2500 $ra = PC + 4; go to 10000 For procedure call

MIPS operands

Name Example Comments$s0-$s7, $t0-$t9, $zero, Fast locations for data. In MIPS, data must be in registers to perform

32 registers $a0-$a3, $v0-$v1, $gp, arithmetic. MIPS register $zero always equals 0. Register $at is $fp, $sp, $ra, $at reserved for the assembler to handle large constants.

Memory[0], Accessed only by data transfer instructions. MIPS uses byte addresses, so

230 memory Memory[4], ..., sequential words differ by 4. Memory holds data structures, such as arrays,

words Memory[4294967292] and spilled registers, such as those saved on procedure calls.

Page 11: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

MIPS CPU Implementation

Register File• Built using D flip-flops

Mux

Register 0

Register 1

Register n – 1

Register n

Mux

Read data 1

Read data 2

Read registernumber 1

Read registernumber 2

Read registernumber 1 Read

data 1

Readdata 2

Read registernumber 2

Register fileWriteregister

Writedata Write

Page 12: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Register File

n-to-1decoder

Register 0

Register 1

Register n – 1C

C

D

DRegister n

C

C

D

D

Register number

Write

Register data

0

1

n – 1

n

Page 13: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Functional units

PC

Instructionmemory

Instructionaddress

Instruction

a. Instruction memory b. Program counter

Add Sum

c. Adder

ALU control

RegWrite

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Writedata

ALUresult

ALU

Data

Data

Registernumbers

a. Registers b. ALU

Zero5

5

5 3

16 32Sign

extend

b. Sign-extension unit

MemRead

MemWrite

Datamemory

Writedata

Readdata

a. Data memory unit

Address

Page 14: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Building the Datapath

PC

Instructionmemory

Readaddress

Instruction

16 32

Add ALUresult

Mux

Registers

Writeregister

Writedata

Readdata 1

Readdata 2

Readregister 1Readregister 2

Shiftleft 2

4

Mux

ALU operation3

RegWrite

MemRead

MemWrite

PCSrc

ALUSrc

MemtoReg

ALUresult

ZeroALU

Datamemory

Address

Writedata

Readdata M

ux

Signextend

Add

Page 15: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Control

PC

Instructionmemory

Readaddress

Instruction[31– 0]

Instruction [20– 16]

Instruction [25– 21]

Add

Instruction [5– 0]

MemtoReg

ALUOp

MemWrite

RegWrite

MemRead

BranchRegDst

ALUSrc

Instruction [31– 26]

4

16 32Instruction [15– 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Shiftleft 2

Mux

1

ALUresult

Zero

Datamemory

Writedata

Readdata

Mux

1

Instruction [15– 11]

ALUcontrol

ALUAddress

Instruction RegDst ALUSrcMemto-

RegReg

WriteMem Read

Mem Write Branch ALUOp1 ALUp0

R-format 1 0 0 1 0 0 0 1 0lw 0 1 1 1 1 0 0 0 0sw X 1 X 0 0 1 0 0 0beq X 0 X 0 0 0 1 0 1

Page 16: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Single/Multi Cycle CPU

Page 17: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Control – FSM

PCWritePCSource = 10

ALUSrcA = 1ALUSrcB = 00ALUOp = 01PCWriteCond

PCSource = 01

ALUSrcA =1ALUSrcB = 00ALUOp= 10

RegDst = 1RegWrite

MemtoReg = 0

MemWriteIorD = 1

MemReadIorD = 1

ALUSrcA = 1ALUSrcB = 10ALUOp = 00

RegDst = 0RegWrite

MemtoReg=1

ALUSrcA = 0ALUSrcB = 11ALUOp = 00

MemReadALUSrcA = 0

IorD = 0IRWrite

ALUSrcB = 01ALUOp = 00

PCWritePCSource = 00

Instruction fetchInstruction decode/

register fetch

Jumpcompletion

BranchcompletionExecution

Memory addresscomputation

Memoryaccess

Memoryaccess R-type completion

Write-back step

(Op

= 'J

')

(Op =

'LW

')

4

01

9862

753

Start

Page 18: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Executing ADD instruction

Page 19: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Executing Load

Page 20: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Executing Store

Page 21: Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture

Executing BEQ