COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York...

28
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single cycle implementation 2. State Diagrams 3. A multiple cycle implementation Patterson: Section 4.4 and Appendix D.1 – D.4

Transcript of COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York...

Page 1: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

COSC 2021: Computer Organization Instructor: Dr. Amir Asif

Department of Computer Science York University Handout # 10

Designing a MIPS Processor I: Control

Topics: 1. A single cycle implementation 2. State Diagrams 3. A multiple cycle implementation

Patterson: Section 4.4 and Appendix D.1 – D.4

Page 2: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

2

Review

Goal: Implement a subset of core instructions from the MIPS instruction set, given below

Category Instruction Example Meaning Comments

Arithmetic and Logical

add add $s1,$s2,$s3 $s1 ← $s2+$s3

subtract sub $s1,$s2,$s3 $s1 ← $s2-$s3

and add $s1,$s2,$s3 $s1 ← $s2&$s3 & => and

or or $s1,$s2,$s3 $s1 ← $s2|$s3 | => or

slt slt $s1,$s2,$s3 If $s1 < $s3, $s1←1 else $s1←0

Data Transfer load word lw $s1,100($s2) $s1 ← Mem[$s2+100]

store word sw $s1,100($s2) Mem[$s2+100] ← $s1

Branch branch on equal beq $s1,$s2,L if($s1==$s2) go to L

unconditional jump j 2500 go to 10000

Page 3: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

3

Combined Datapath

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n

1 6 3 2

A d d A L U r e s u l t

M u x

R e g i s t e r s

W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S h i f t l e f t 2

4

M u x

A L U o p e r a t i o n 3

R e g W r i t e

M e m R e a d

M e m W r i t e

P C S r c

A L U S r c M e m t o R e g

A L U r e s u l t

Z e r o A L U

D a t a m e m o r y

A d d r e s s

W r i t e d a t a

R e a d d a t a M

u x

S i g n e x t e n d

A d d

Page 4: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

4

Combined Datapath: Arithmetic Operations (add,sub,or,and,slt)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n

1 6 3 2

A d d A L U r e s u l t

M u x

R e g i s t e r s

W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S h i f t l e f t 2

4

M u x

A L U o p e r a t i o n 3

R e g W r i t e

M e m R e a d

M e m W r i t e

P C S r c

A L U S r c M e m t o R e g

A L U r e s u l t

Z e r o A L U

D a t a m e m o r y

A d d r e s s

W r i t e d a t a

R e a d d a t a M

u x

S i g n e x t e n d

A d d

add/sub/or/and/slt $s1,$s2,$s3

Page 5: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

5

Combined Datapath: Data Transfer (load)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n

1 6 3 2

A d d A L U r e s u l t

M u x

R e g i s t e r s

W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S h i f t l e f t 2

4

M u x

A L U o p e r a t i o n 3

R e g W r i t e

M e m R e a d

M e m W r i t e

P C S r c

A L U S r c M e m t o R e g

A L U r e s u l t

Z e r o A L U

D a t a m e m o r y

A d d r e s s

W r i t e d a t a

R e a d d a t a M

u x

S i g n e x t e n d

A d d

lw $s1, offset($s2)

Page 6: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

6

Review: Data Transfer (store)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n

1 6 3 2

A d d A L U r e s u l t

M u x

R e g i s t e r s

W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S h i f t l e f t 2

4

M u x

A L U o p e r a t i o n 3

R e g W r i t e

M e m R e a d

M e m W r i t e

P C S r c

A L U S r c M e m t o R e g

A L U r e s u l t

Z e r o A L U

D a t a m e m o r y

A d d r e s s

W r i t e d a t a

R e a d d a t a M

u x

S i g n e x t e n d

A d d

sw $s1, offset($s2)

Page 7: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

7

Review: Data Transfer (branch)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n

1 6 3 2

A d d A L U r e s u l t

M u x

R e g i s t e r s

W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S h i f t l e f t 2

4

M u x

A L U o p e r a t i o n 3

R e g W r i t e

M e m R e a d

M e m W r i t e

P C S r c

A L U S r c M e m t o R e g

A L U r e s u l t

Z e r o A L U

D a t a m e m o r y

A d d r e s s

W r i t e d a t a

R e a d d a t a M

u x

S i g n e x t e n d

A d d

beq $s1, $s2, w_offset

Page 8: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

8

Types of Datapath

—  Datapaths can be divided into two categories 1.  Single cycle datapath: An instruction (e.g. lw) is performed in 1 clock cycle 2.  Multiple cycle datapath: An instruction is performed in multiple clock cycles

—  Advantage of single datapath: Keeps the design simpler —  Disadvantage of single datapath:

1.  No datapath resource can be used more than once in a clock cycle 2.  Elements being accessed more than once in an instruction be duplicated

or have multiple inputs and outputs. 3.  An instruction memory separate from data memory is required

—  In section 4.4, a single cycle datapath is considered. We expand the discussion to multiple cycle datapaths later.

Page 9: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

9

Control

—  What needs to be added to complete the design of the single cycle datapath? —  Control Unit activates appropriate controls at

1.  ALU 2.  MUX’s (3) 3.  Read/write signals for register file 4.  Read/write signals for data memory

—  Consider the design of the ALU Control Unit

ALU Control Lines Result

0000 AND

0001 OR

0010 Add

0110 Subtract

0111 SLT

1100 NOR

A L U R e s u l t Z e r o

O v e r f l o w

a

b

A L U o p e r a t i o n

C a r r y O u t

4

1

Page 10: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

10

Control: ALU Control Unit (1)

3

A L U Z e r o

ALU result

a

b

ALU Control

Instructions [5-0]

ALUOp

5

4

2

—  Inputs to ALU Control: 1.  Function fields of instructions 2.  2-bit control field (ALUOp) —  Output of ALU Control: 1.  4-bit signal that controls the ALU

Page 11: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

11

Control: ALU Control Unit (2)

1.  I-format instructions (lw/sw/beq) does not have a function field 2.  Use ALUOp to differentiate the operation from the rest

e.g., ALUOp = 00 for lw/sw; ALUOp = 01 for beq

I-format: op (31 – 26) rs (25 – 21) rt (20 – 16) Immediate / Offset (15 – 0)

R-format: op (31 – 26) rs (25 – 21) rt (20 – 16) rd (15 – 11) shamt (10 – 6) funct (5 – 0)

1.  R-format instructions (add/sub/and/or) does have a function field 2.  ALUOp = 10 for all instructions 3.  Function field is 32 for add, 34 for sub, 36 for AND, 37 for OR, and 42 for SLT

Page 12: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

12

Control: ALU Control Unit (3)

Instruction (opcode)

Inputs

Desired ALU action

Outputs Operation (Op3 – Op0) ALUOp

(ALUOp1 – ALUOp0) Function Field

(F5 – F0)

lw (I) 0 0 X X X X X X add 0 0 1 0

sw (I) 0 0 X X X X X X add 0 0 1 0

beq (I) 0 1 X X X X X X sub 0 1 1 0

add (32) 1 0 1 0 0 0 0 0 add 0 0 1 0

sub (34) 1 0 1 0 0 0 1 0 sub 0 1 1 0

and (36) 1 0 1 0 0 1 0 0 and 0 0 0 0

or (37) 1 0 1 0 0 1 0 1 or 0 0 0 1

slt (42) 1 0 1 0 1 0 1 0 slt 0 1 1 1

1.  The first two rows of the truth table are the same. 2.  Number of inputs in the truth table are 6 while number of rows in the table are 8. 3.  Only 8 of the 26 = 32 possible combinations of input are being used. 4.  Some “DO NOT CARE” entries can be added to simplify the above truth table.

Page 13: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

13

Control: ALU Control Unit (4)

Instruction (opcode)

Inputs

Desired ALU action

Outputs Operation (Op3 – Op0) ALUOp

(ALUOp1 – ALUOp0) Function Field

(F5 – F0)

lw (I) 0 0 (0 0) X X X X X X add 0 0 1 0

sw (I) 0 0 (0 0) X X X X X X add 0 0 1 0

beq (I) 0 1 (0 1) X X X X X X sub 0 1 1 0

add (32) 1 0 (1 0) X X 0 0 0 0 add 0 0 1 0

sub (34) 1 X (1 0) X X 0 0 1 0 sub 0 1 1 0

and (36) 1 0 (1 0) X X 0 1 0 0 and 0 0 0 0

or (37) 1 0 (1 0) X X 0 1 0 1 or 0 0 0 1

slt (42) 1 X (1 1) X X 1 0 1 0 slt 0 1 1 1

ALUOp does not use encoding 11, so, 10 and 11 may be replaced with 1X. The first two fields of the function fields are always 10, so, they are replaced by XX.

Page 14: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

14

Control: ALU Control Unit (4)

Op2 = ALUOp0+ ALUOP1⋅F1

Simplified Expressions:

The truth table above shows the input combinations for which the ALU Control should be 0010, 0001, 0110, or 0111 (the other combinations are not used).

ALUOp Function code fields ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0

0 1 X X X X X X

1 X X X X X(0) 1 X(0)

Truth Table for Operation2 = 1:

Page 15: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

15

Control: ALU Control Unit (4)

Op1= ALUOp1+ F2Op2 = ALUOp0+ ALUOP1⋅F1

Simplified Expressions:

ALUOp Function code fields ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0

0 X X X X X X X

X(1) X X X X 0 X(1) X(0)

Truth Table for Operation1 = 1:

Page 16: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

16

Control: ALU Control Unit (4)

Op0 = ALUOp1⋅ (F0+ F3)Op1= ALUOp1+ F2Op2 = ALUOp0+ ALUOP1⋅F1

Simplified Expressions:

ALUOp Function code fields ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0

1 X X X X X X 1

1 X X X 1 X X X

Truth Table for Operation0 = 1:

Page 17: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

17

Control: ALU Control Unit (5)

Combinational Circuit for the ALU Control Unit

O p e r a t i o n 2

O p e r a t i o n 1

O p e r a t i o n 0

O p e r a t i o n

A L U O p 1

F 3

F 2

F 1

F 0

F ( 5 – 0 )

A L U O p 0

A L U O p A L U c o n t r o l b l o c k

Op0 = ALUOp1⋅ (F0+ F3)Op1= ALUOp1+ F2Op2 = ALUOp0+ ALUOP1⋅F1

Page 18: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

18

Main Control (1)

I-format: op (31 – 26) rs (25 – 21) rt (20 – 16) Immediate / Offset (15 – 0)

R-format: op (31 – 26) rs (25 – 21) rt (20 – 16) rd (15 – 11) shamt (10 – 6) funct (5 – 0)

1.  Opcode is contained in bits 31 – 26. 2.  Registers specified by rs (bits 25 – 21) and rt (bits 20 – 16) are always read 3.  Base register (w/ base address) for lw/sw instruction is specified by rs (bits 25–21) 4.  16-bit offset for beq, lw, and sw is always specified in bits 15 – 0. 5.  Destination register is specified in one of the two places:

—  For R-type instructions (add/sub/and/or), destination register is specified by bits (15 – 11)

—  For lw instruction, destination register is specified by bits (20 – 16)

Using information (1 – 5), we can add the instruction labels and additional MUX’s to the datapath that we have constructed.

Page 19: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

19

Main Control (2)

M e m t o R e g

M e m R e a d

M e m W r i t e

A L U O p

A L U S r c

R e g D s t

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n [ 3 1 – 0 ]

I n s t r u c t i o n [ 2 0 – 1 6 ] I n s t r u c t i o n [ 2 5 – 2 1 ]

A d d

I n s t r u c t i o n [ 5 – 0 ]

R e g W r i t e 4

1 6 3 2 I n s t r u c t i o n [ 1 5 – 0 ] 0

R e g i s t e r s

W r i t e r e g i s t e r W r i t e d a t a

W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S i g n e x t e n d

A L U r e s u l t Z e r o

D a t a m e m o r y

A d d r e s s R e a d d a t a M

u x

1

1 M u x

0

1 M u x

0

1 M u x

0 I n s t r u c t i o n [ 1 5 – 1 1 ]

A L U c o n t r o l

S h i f t l e f t 2

P C S r c

A L U

A d d A L U r e s u l t

Number of control lines is 10 (4 for MUX’s, 3 for ALU control, 2 for data memory, 1 for register file)

Page 20: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

20

Main Control (3) Control Input Effect when Deasserted (0) Effect when asserted (1)

RegDst Destination register number comes from bits 20 – 16 of the instruction (sw)

Destination register number comes from bits 15 – 11 of the instruction (add,sub,or,and,slt)

Regwrite None Data on the “write data” input is written on the register specified on the “write register” input (lw, add,sub,or,and)

ALUSrc Second operand to ALU comes from the second register file output (add,sub,or,and,beq,slt)

Second operand to ALU is sign extended, lower 16 bits of instruction(lw,sw)

MemRead None Data from memory location specified by “address” input is placed on the “read data” output (lw)

MemWrite None Data from “write data” input replaces memory location specified by “address” input (sw)

MemtoReg Data from the output of ALU is fed into “write data” input of the register file (add,sub,or,and,slt)

Data from the “read data” output of data memory is fed into “write data” input of the register file (lw)

PCSrc PC is replaced by the output of adder which adds 4 to the existing content of PC (except for beq)

PC is replaced by the output of adder which computes branch target by adding existing content of PC with 2-bit right shifted offset (beq)

Next step in the design of datapath is to add a control unit that generates the control inputs to MUX’s

Page 21: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

21

Main Control (4)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n [ 3 1 – 0 ]

I n s t r u c t i o n [ 2 0 1 6 ]

I n s t r u c t i o n [ 2 5 2 1 ]

A d d

I n s t r u c t i o n [ 5 0 ]

M e m t o R e g A L U O p M e m W r i t e

R e g W r i t e

M e m R e a d B r a n c h R e g D s t

A L U S r c

I n s t r u c t i o n [ 3 1 2 6 ]

4

1 6 3 2 I n s t r u c t i o n [ 1 5 0 ]

0

0 M u x

0

1

C o n t r o l

A d d A L U r e s u l t

M u x

0

1

R e g i s t e r s W r i t e r e g i s t e r

W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1

R e a d r e g i s t e r 2

S i g n e x t e n d

M u x

1

A L U r e s u l t

Z e r o

P C S r c

D a t a m e m o r y W r i t e

d a t a

R e a d d a t a M

u x

1

I n s t r u c t i o n [ 1 5 1 1 ]

A L U c o n t r o l

S h i f t l e f t 2

A L U A d d r e s s

Page 22: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

22

Main Control (5)

Instruction RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOp0

R-format 1 0 0 1 0 0 0 1 0

lw 0 1 1 1 1 0 0 0 0

sw X 1 X 0 0 1 0 0 0

beq X 0 X 0 0 0 1 0 1

Inputs of Control Unit:

Outputs of Control Unit:

Instruction Opcode in Decimal

Opcode in Binary

Op5 Op4 Op3 Op2 Op1 Op0

R-format 0ten 0 0 0 0 0 0

lw 35ten 1 0 0 0 1 1

sw 43ten 1 0 1 0 1 1

beq 4ten 0 0 0 1 0 0

which constitutes the truth table

Page 23: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

23

Main Control (6)

R - f o r m a t I w s w b e q

O p 0 O p 1 O p 2 O p 3 O p 4 O p 5

I n p u t s

O u t p u t s

R e g D s t

A L U S r c M e m t o R e g R e g W r i t e M e m R e a d M e m W r i t e

B r a n c h A L U O p 1

A L U O p O

Page 24: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

24

Example: R-type Instruction (step1: fetch instruction & increment PC)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n [ 3 1 – 0 ]

I n s t r u c t i o n [ 2 0 – 1 6 ] I n s t r u c t i o n [ 2 5 – 2 1 ]

A d d

I n s t r u c t i o n [ 5 – 0 ]

M e m t o R e g A L U O p M e m W r i t e R e g W r i t e

M e m R e a d B r a n c h R e g D s t

A L U S r c

I n s t r u c t i o n [ 3 1 – 2 6 ] 4

1 6 3 2 I n s t r u c t i o n [ 1 5 – 0 ]

0

0 M u x 0

1

C o n t r o l

A d d A L U r e s u l t

M u x

0

1

R e g i s t e r s W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S i g n e x t e n d

S h i f t l e f t 2

M u x

1

A L U r e s u l t Z e r o

D a t a m e m o r y

W r i t e d a t a

R e a d d a t a

M u x 1

I n s t r u c t i o n [ 1 5 – 1 1 ]

A L U c o n t r o l

A L U A d d r e s s

Step 1 1. Fetch instruction 2. Add 4 to the value of PC

Page 25: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

25

Example: R-type Instruction (step2: Read two source registers)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n [ 3 1 – 0 ]

I n s t r u c t i o n [ 2 0 – 1 6 ] I n s t r u c t i o n [ 2 5 – 2 1 ]

A d d

I n s t r u c t i o n [ 5 – 0 ]

M e m t o R e g A L U O p M e m W r i t e R e g W r i t e

M e m R e a d B r a n c h R e g D s t

A L U S r c

I n s t r u c t i o n [ 3 1 – 2 6 ] 4

1 6 3 2 I n s t r u c t i o n [ 1 5 – 0 ]

0

0 M u x

0

1

C o n t r o l

A d d A L U r e s u l t

M u x

0

1

R e g i s t e r s W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S i g n e x t e n d

S h i f t l e f t 2

M u x

1

A L U r e s u l t Z e r o

D a t a m e m o r y

W r i t e d a t a

R e a d d a t a

M u x 1

I n s t r u c t i o n [ 1 5 – 1 1 ]

A L U c o n t r o l

A L U A d d r e s s

Step 2: 1. Source registers are read from the register file 2. Control unit uses the opcode to activate units. ALUOp = 10 set based on opcode

Page 26: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

26

Example: R-type Instruction (step3: ALU operates on operands)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n [ 3 1 – 0 ]

I n s t r u c t i o n [ 2 0 1 6 ] I n s t r u c t i o n [ 2 5 2 1 ]

A d d

I n s t r u c t i o n [ 5 0 ]

M e m t o R e g A L U O p M e m W r i t e R e g W r i t e

M e m R e a d B r a n c h R e g D s t

A L U S r c

I n s t r u c t i o n [ 3 1 2 6 ] 4

1 6 3 2 I n s t r u c t i o n [ 1 5 0 ]

0

0 M u x

0

1

A L U c o n t r o l

C o n t r o l

A d d A L U r e s u l t

M u x

0

1

R e g i s t e r s W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1

R e a d d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S i g n e x t e n d

M u x

1

A L U r e s u l t Z e r o

D a t a m e m o r y

R e a d d a t a A d d r e s s

W r i t e d a t a

M u x 1

I n s t r u c t i o n [ 1 5 1 1 ]

A L U

S h i f t l e f t 2

Step 3: 1. ALUSrc = 0 2. Control line values of ALU set by ALU-control 2. ALU performs desired operation on input data

Page 27: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

27

Example: R-type Instruction (step 4: Write result in destination register)

P C

I n s t r u c t i o n m e m o r y

R e a d a d d r e s s

I n s t r u c t i o n [ 3 1 – 0 ]

I n s t r u c t i o n [ 2 0 1 6 ] I n s t r u c t i o n [ 2 5 2 1 ]

A d d

I n s t r u c t i o n [ 5 0 ]

M e m t o R e g A L U O p M e m W r i t e R e g W r i t e

M e m R e a d B r a n c h R e g D s t

A L U S r c

I n s t r u c t i o n [ 3 1 2 6 ] 4

1 6 3 2 I n s t r u c t i o n [ 1 5 0 ]

0

0 M u x 0

1

A L U c o n t r o l

C o n t r o l

S h i f t l e f t 2

A d d A L U r e s u l t

M u x

0

1

R e g i s t e r s W r i t e r e g i s t e r W r i t e d a t a

R e a d d a t a 1 R e a d

d a t a 2

R e a d r e g i s t e r 1 R e a d r e g i s t e r 2

S i g n e x t e n d

M u x 1

A L U r e s u l t Z e r o

D a t a m e m o r y

W r i t e d a t a

R e a d d a t a

M u x 1

I n s t r u c t i o n [ 1 5 1 1 ]

A L U A d d r e s s

Step 4: 1. MemtoReg = 0; RegDst = 1; 2. Result of ALU is written in specified register 3. PC is incremented by 4

Page 28: COSC 2021: Computer Organization ... - York Universityasif/2021Fall10/handout10_1slide.pdf · York University Handout # 10 Designing a MIPS Processor I: Control Topics: 1. A single

28

Why single-cycle implementation is not used?

Assuming no delay at adder, sign extension unit, shift left unit, PC, control unit, and MUX:

—  Load cycle requires 5 functional units: instruction fetch, register access, ALU, data memory access, register access

—  Store cycle requires 4 functional units: instruction fetch, register access, ALU, data memory access

—  R-type instruction cycle requires 4 functional units: instruction fetch, register access, ALU, register access

—  Path for a branch instruction requires 3 functional units: instruction fetch, register access, ALU

—  Path for a jump instruction requires 1 functional unit: instruction fetch

Using a clock cycle of equal duration for each instruction is a waste of resources.