CC 311- Computer Architecture. The Processor - Control

Similar documents
Systems Architecture I

Lecture 5 and 6. ICS 152 Computer Systems Architecture. Prof. Juan Luis Aragón

CPE 335. Basic MIPS Architecture Part II

ENE 334 Microprocessors

The Processor: Datapath & Control

Topic #6. Processor Design

ECE369. Chapter 5 ECE369

Lets Build a Processor

Mapping Control to Hardware

CSE 2021 COMPUTER ORGANIZATION

Initial Representation Finite State Diagram. Logic Representation Logic Equations

LECTURE 6. Multi-Cycle Datapath and Control

Processor: Multi- Cycle Datapath & Control

CSE 2021 COMPUTER ORGANIZATION

Implementing the Control. Simple Questions

ﻪﺘﻓﺮﺸﻴﭘ ﺮﺗﻮﻴﭙﻣﺎﻛ يرﺎﻤﻌﻣ MIPS يرﺎﻤﻌﻣ data path and ontrol control

Chapter 4 The Processor (Part 2)

Multicycle Approach. Designing MIPS Processor

Chapter 5: The Processor: Datapath and Control

ALUOut. Registers A. I + D Memory IR. combinatorial block. combinatorial block. combinatorial block MDR

RISC Processor Design

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Data Paths and Microprogramming

Initial Representation Finite State Diagram Microprogram. Sequencing Control Explicit Next State Microprogram counter

Chapter 5 Solutions: For More Practice

5.7. Microprogramming: Simplifying Control Design 5.7

Processor (I) - datapath & control. Hwansoo Han

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 4: Datapath and Control

ECE468 Computer Organization and Architecture. Designing a Multiple Cycle Controller

Major CPU Design Steps

Systems Architecture

Inf2C - Computer Systems Lecture 12 Processor Design Multi-Cycle

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

RISC Architecture: Multi-Cycle Implementation

Microprogrammed Control Approach

Control Unit for Multiple Cycle Implementation

Multiple Cycle Data Path

Points available Your marks Total 100

EECE 417 Computer Systems Architecture

Multicycle conclusion

Alternative to single cycle. Drawbacks of single cycle implementation. Multiple cycle implementation. Instruction fetch

Note- E~ S. \3 \S U\e. ~ ~s ~. 4. \\ o~ (fw' \i<.t. (~e., 3\0)

RISC Design: Multi-Cycle Implementation

CO Computer Architecture and Programming Languages CAPL. Lecture 18 & 19

LECTURE 5. Single-Cycle Datapath and Control

Lecture 5: The Processor

CENG 3420 Lecture 06: Datapath

COMPUTER ORGANIZATION AND DESIGN. The Hardware/Software Interface. Chapter 4. The Processor: A Based on P&H

Review: Abstract Implementation View

CS152 Computer Architecture and Engineering Lecture 13: Microprogramming and Exceptions. Review of a Multiple Cycle Implementation

Chapter 4. The Processor. Computer Architecture and IC Design Lab

RISC Architecture: Multi-Cycle Implementation

CENG 3420 Computer Organization and Design. Lecture 06: MIPS Processor - I. Bei Yu

CS152 Computer Architecture and Engineering. Lecture 8 Multicycle Design and Microcode John Lazzaro (

CPE 335 Computer Organization. Basic MIPS Architecture Part I

Design of the MIPS Processor

Lecture 8: Control COS / ELE 375. Computer Architecture and Organization. Princeton University Fall Prof. David August

Multi-cycle Approach. Single cycle CPU. Multi-cycle CPU. Requires state elements to hold intermediate values. one clock cycle or instruction

Computer Science 141 Computing Hardware

THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY Computer Organization (COMP 2611) Spring Semester, 2014 Final Examination

The Processor. Z. Jerry Shi Department of Computer Science and Engineering University of Connecticut. CSE3666: Introduction to Computer Architecture

TDT4255 Computer Design. Lecture 4. Magnus Jahre. TDT4255 Computer Design

ECE 313 Computer Organization FINAL EXAM December 14, This exam is open book and open notes. You have 2 hours.

Microprogramming. Microprogramming

The Processor: Datapath & Control

CSEN 601: Computer System Architecture Summer 2014

CSE 2021: Computer Organization Fall 2010 Solution to Assignment # 3: Multicycle Implementation

The Processor (1) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Chapter 4. Instruction Execution. Introduction. CPU Overview. Multiplexers. Chapter 4 The Processor 1. The Processor.

Computer Architecture Chapter 5. Fall 2005 Department of Computer Science Kent State University

ECE 3056: Architecture, Concurrency and Energy of Computation. Single and Multi-Cycle Datapaths: Practice Problems

ECE232: Hardware Organization and Design

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Design of the MIPS Processor (contd)

CPU Organization (Design)

Computer Organization & Design The Hardware/Software Interface Chapter 5 The processor : Datapath and control

Chapter 4. The Processor

Using a Hardware Description Language to Design and Simulate a Processor 5.8

Introduction. ENG3380 Computer Organization and Architecture MIPS: Data Path Design Part 3. Topics. References. School of Engineering 1

Processor (multi-cycle)

Chapter 4. The Processor

Processor Implementation in VHDL. University of Ulster at Jordanstown University of Applied Sciences, Augsburg

EE457. Note: Parts of the solutions are extracted from the solutions manual accompanying the text book.

The MIPS Processor Datapath

Mark Redekopp and Gandhi Puvvada, All rights reserved. EE 357 Unit 15. Single-Cycle CPU Datapath and Control

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 4. The Processor. Instruction count Determined by ISA and compiler. We will examine two MIPS implementations

ECE 313 Computer Organization EXAM 2 November 9, 2001

Single vs. Multi-cycle Implementation

Chapter 4 The Processor 1. Chapter 4A. The Processor

Single Cycle CPU Design. Mehran Rezaei

CS Computer Architecture Spring Week 10: Chapter

Inf2C - Computer Systems Lecture Processor Design Single Cycle

CS232 Final Exam May 5, 2001

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CpE 442. Designing a Multiple Cycle Controller

Chapter 4. The Processor Designing the datapath

COMP303 - Computer Architecture Lecture 10. Multi-Cycle Design & Exceptions

ECE 361 Computer Architecture Lecture 11: Designing a Multiple Cycle Controller. Review of a Multiple Cycle Implementation

Transcription:

CC 311- Computer Architecture The Processor - Control

Control Unit Functions: Instruction code Control Unit Control Signals Select operations to be performed (ALU, read/write, etc.) Control data flow (multiplexor inputs) Major components: ALU control ALU's operation is based on instruction type and function code Will be designed first Other controls Input: Information comes from the 32 bits of the instruction Output: Control signals 2

Review: MIPS Instruction Format R-type 31 26 21 16 11 6 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 0 I-type 31 26 21 16 op rs rt immediate 6 bits 5 bits 5 bits 16 bits 0 J- type 31 26 op target address 6 bits 26 bits 0 3

Observations on Instruction Format The opcode field is always in bits 31:26. will be referred to as (Op[5:0]) For R-type, branch equal, and store instructions, the two registers to read are always rs and rt in bits 25:21 and 20:16 respectively For load and store instructions, the base register, rs, is always in bits 25:21 For branch equal, load, and store, the 16-bit offset is always in positions 15:0 The destination register is in one of two places For load, the destination register (rt) is in position 20:16 For R-type instructions, destination register (rd) is in positions 15:11 => A MUX is needed to select which field of the instruction is used to indicate the destination register 4

ALU Control Summary ALU control Action 0000 AND 0001 OR 0010 add 0110 subtract 0111 set-on-less-than 1100 NOR The ALU has 4 control inputs Allows 16 possible combinations Only 6 combinations are used. The rest could be used as don t-care in minimization 5

ALU Control Remember: ALU is needed for all instruction categories lw and sw (I-Format): Compute memory address Arithmetic/logic(R-Format): Perform arithmetic / logic operation Branch(beq)(I-Format): Subtract registers We need to find ALU control signals from the information in the instruction 6

ALU Control How ALU control bits are set ALUOp = 00 or 01 They are of I-type format Depend on op field & does not depend on funct field lw: 100011 sssss ttttt iiiiiiiiiiiiiiii sw: 101011 sssss ttttt iiiiiiiiiiiiiiii 000100 sssss ttttt iiiiiiiiiiiiiiii beq: => Don t care s are used XXXXXX for funct field ALUOp code = 10 Are of R-type instructions Depend on funct field => funct code is used to set the ALU control input 7

ALU Control How the ALU control bits are set depends on ALUOp control bits and the different function codes for R-type instructions See fig 5.12, p. 302 Instruction Opcode Instruction operation Desired ALU action ALU control input ALUOp Funct field lw 00 load word XXXXXX add 0010 sw 00 store word XXXXXX add 0010 Branch equal 01 branch equal XXXXXX subtract 0110 R-type 10 add 100000 add 0010 R-type 10 subtract 100010 subtract 0110 R-type 10 AND 100100 and 0000 R-type 10 OR 100101 or 0001 R-type 10 set on less than 101010 set on less than 0111 R-type 11 nor 100111 nor 1100 8

ALU Control Truth table for the 4 ALU control bits See Fig 5.13, p. 302 Once the truth table is constructed, it can be optimized and turned into gates 9

Truth Tables for ALU Control Bits We need to find the logical functions for O3, O2, O1, and O0 ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 0 0 X X X X X X 0 0 1 0 lw/sw X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 0 0 0 0 1 0 add 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 0 1 0 0 0 0 0 0 and 1 X X X 0 1 0 1 0 0 0 1 or 1 X X X 1 0 1 0 0 1 1 1 sll 1 1 X X 0 1 1 1 1 1 0 0 nor 10

Truth Tables for ALU Control Bits For Operation O3 = 1 ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 0 0 X X X X X X 0 0 1 0 lw/sw X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 0 0 0 0 1 0 add 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 0 1 0 0 0 0 0 0 and 1 X X X 0 1 0 1 0 0 0 1 or 1 X X X 1 0 1 0 0 1 1 1 sll 1 1 X X 0 1 1 1 1 1 0 0 nor ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 1 1 X X 0 1 1 1 1 1 0 0 nor O3 = ALUOp1. ALUOp0. F3.F2.F1.F0 ALUOp Funct field ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 1 1 X X 0 1 1 1 11

Truth Tables for ALU Control Bits For Operation O2 = 1 ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 0 0 X X X X X X 0 0 1 0 lw/sw X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 0 0 0 0 1 0 add 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 0 1 0 0 0 0 0 0 and 1 X X X 0 1 0 1 0 0 0 1 or 1 X X X 1 0 1 0 0 1 1 1 sll 1 1 X X 0 1 1 1 1 1 0 0 nor ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 1 0 1 0 0 1 1 1 sll 1 1 X X 0 1 1 1 1 1 0 0 nor ALUOp Funct field ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 X 1 X X X X X X 1 X X X X 0 1 0 1 1 X X 0 1 1 1 O2 = ALUOp1.ALUOp0 ALUOp Funct field ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 1 1 X X X X X X 12

Truth Tables for ALU Control Bits For Operation O1 =1 ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 0 0 X X X X X X 0 0 1 0 lw/sw X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 0 0 0 0 1 0 add 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 0 1 0 0 0 0 0 0 and 1 X X X 0 1 0 1 0 0 0 1 or 1 X X X 1 0 1 0 0 1 1 1 sll 1 1 X X 0 1 1 1 1 1 0 0 nor ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 0 0 X X X X X X 0 0 1 0 lw/sw X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 0 0 0 0 1 0 add 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 1 0 1 0 0 1 1 1 sll O1 = ALUOp1. ALUOp0 + ALOP1.ALUOp0 ALUOp Funct field ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 0 0 X X X X X X X 1 X X X X X X 1 X X X X 0 X 0 ALUOp Funct field ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 0 0 X X X X X X 1 1 X X X X X X 13

Truth Tables for ALU Control Bits For Operation O0 =1 ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 0 0 X X X X X X 0 0 1 0 lw/sw X 1 X X X X X X 0 1 1 0 beq 1 X X X 0 0 0 0 0 0 1 0 add 1 X X X 0 0 1 0 0 1 1 0 sub 1 X X X 0 1 0 0 0 0 0 0 and 1 X X X 0 1 0 1 0 0 0 1 or 1 X X X 1 0 1 0 0 1 1 1 sll 1 1 X X 0 1 1 1 1 1 0 0 nor ALUOp Funct field Operation Instruction ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 O3 O2 O1 O0 1 X X X 0 1 0 1 0 0 0 1 or 1 X X X 1 0 1 0 0 1 1 1 sll O0 = ALUOp1 ALUOp Funct field ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 1 X X X X X X X 14

ALU Control: Logic Circuit Based on funct code & ALUOp Details in Appendix C2 (Have some errors/incomplete) O3 = ALUOp1.ALUOp0.F3.F2.F1.F0 O2 = ALUOp1.ALUOp0 O1 = O1 = ALUOp1.ALUOp0 + ALOP1.ALUOp0 O0 = ALUOp1 Exercise: Draw the correct logic diagram ALUOp 2 ALU Control Circuit Diagram ALUOp0 ALUOp1 F 3? Operation3 Operation2 F ( 5 0 ) F 2 Operation1 F 1 6 Operation0 F 0 ALU operation (Control signals) 4 15

ALU Control The datapath with necessary multiplexors and all control lines 16

ALU Control 9 control lines 2 for ALUOp 00 for load/store 10 for R-Format 01 for other operations RegDst RegWrite ALUSrc PCSrc MemRead MemWrite MemtoReg All signals except PCSrc are set from the opcode field PCSrc is set when the code is for a branch instruction and Zero signal is set To generate PCSrc signal, we use an AND gate with the zero signal from ALU See fig. 5.16, p. 306 for the effect of the control signals when they are asserted or de-asserted respectively 17

ALU Control Effect of the control signals when they are asserted or de-asserted respectively See fig. 5.16, p. 306 Signal name If de-asserted (0) If asserted (1) RegDst Destination register <= rt field (20-16) Destination register <= rd field (15-11) RegWrite None Write data input => Write register ALUSrc Reg Data2 => 2nd ALU operand Sign-extnd 16-bits of instruction => 2nd ALU operand PCSrc PC <= PC + 4 (from adder) PC <= Branch target (from adder) MemRead None Mem[Address] => to Read data output MemWrite None Mem[Address] <= value on Write data input MemtoReg Value to Write data input comes from ALUValue to Write data input comes from data memory 18

ALU Control The simple datapath with the control unit 19

Main Control Unit Input: 6-bit opcode field from the instruction Output: 9 signals 3 signals for multiplexors RegDest MemtoReg ALUSrc 3 signals to control reads & writes in register file & data memory RegWrite MemRead MemWrite 1 signal to control whether to Branch or not Branch 2 signals for ALU ALUOp 20

Main Control Unit Mapping the Functions to Gates See Fig C.2.5, Appendix C, p. c-8 I n p u t (6-bits Op code) O p 5 O p 4 O p 3 O p 2 O p 1 O p 0 000000 100011 101011 000100 R - f o r m a t I w s w b e q O u t p u t (Control signals 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 21

Main Control Unit Control lines needed by each instruction R-Format (add, sub, AND, OR, & slt) Source register : rs & rt Destination register: rd Writes a register (RegWrite = 1) but neither reads nor writes data memory ALUOp for R-Type format = 10 indicating that ALU control should be generated from function field When Branch: Control signal = 0, PC<= PC +4; Otherwise it is replaced by Branch target For lw MemRead = 1, for sw MemWrite = 1 See Fig 5.18, p. 308 Instruction RegDest ALUSrc MemtoReg RegWrite MemRead MemWrite Banch 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 22

Datapath Operation for R-Format (add) Add $t1, $t2, $t3 Step1: Fetch instruction from instruction memory Increment program counter Step2: Decode result is Add operation Read two registers $t2 & $t3 from register file Step 3: ALU operates on data, using funct field code to generate the ALU function Step4: Idle Step5: Write result of step 3 from ALU into register $t1 Note: Step1 is the same for all instructions 23

Datapath Operation for R-Format (add) Add $t1, $t2, $t3 (Fig. 5.19, p. 309) 24

Multicycle Implementation Each instruction is broken into a series of steps corresponding to the functional unit operations needed Each step executes in one clock cycle Advantages: Allows functional units to be used more than once per instruction Help reduce HW cost 25

Multicycle Implementation Major difference from single cycle datapath: Single memory unit used for both instruction and data Single ALU instead of three One or more registers are added after every major functional unit to hold the output of that unit until the value is used in subsequent clock cycle Added registers Instruction register (IR) Saves output from memory for instruction read Memory data register (MDR) Saves output from memory for data read A and B registers Hold the register operands read from register file ALUOut register Holds the output from ALU 26

Multicycle Implementation Multicycle datapath supporting jump and branch instructions 27

Breaking Instructions Each step will contain at most One ALU operation One register file access One memory access At the end of each cycle, data values needed for subsequent cycle must be stored into a register Since the design is edge triggered, current value of a register can be read during that clock cycle period until the next edge All operations listed in one step occur in parallel Successive steps occur in a series of different clock cycles Each MIPS instruction will need 3 to 5 steps 28

Breaking Instructions Steps: 1. Instruction fetch 2. Instruction decode & register fetch 3. Execution, memory address computation, or branch completion 4. Memory access or R-type instruction completion 5. Memory read completion 29

Breaking Instructions 1. Instruction fetch Action taken (in Verilog terminology) IR <= Memory[PC] PC <= PC + 4 Control signals required MemRead asserted IRWrite asserted IorD set to 0 (to select PC) ALUSrcA set to 0 ALUSrcB set to 01 (to send 4 to ALU) ALUOp set to 00 (choose addition) PCSource set to 00 PCWrite asserted 30

Breaking Instructions 2. Instruction decode & register fetch Action taken A <= Reg[IR[25:21]]; (R-Format) B <= Reg[IR[20:16]]; (for branch instruction) ALUOut <= PC + (sign-extend (IR[15:0] ) << 2); Control signals required ALUSrcA set to 0 ALUSrcB set to 11 (sign extend and shift offset sent to ALU) ALUOp set to 00 (choose addition) 31

Breaking Instructions 3. Execution, memory address computation, or branch completion Determined by the instruction class Memory reference instruction Action taken ALUOut <= A + signextend (IR[15:0]); Control signals required ALUSrcA set to 1 ALUSrcB set to 10 (sign extend and shift offset sent to ALU) ALUOp set to 00 (choose addition) Arithmetic-logical Action taken ALUOut <= A op B; Control signals required ALUSrcA set to 1 ALUSrcB set to 00 ALUOp set to 10(determined by funct field) 32

Breaking Instructions 3. Execution, memory address computation, or branch completion Determined by the instruction class Branch Action taken if (A == B) PC <= ALUOut; Control signals required ALUSrcA set to 1 ALUSrcB set to 00 ALUOp set to 01 (for subtract) PCWrite asserted PCSource seet to 01 Jump Action taken PC <= {PC [31:28], IR[25:0]], 2 b00)}; Control signals required PCWrite asserted PCSource seet to direct the jump address to the PC 33

Breaking Instructions 4. Memory access or R-type instruction completion Determined by the instruction class Memory reference (load or store) Action taken MDR <= Memory[ALUOut]; or Memory [ALUOut] <= B; Control signals required MemRead asserted (for load) MemWrite asserted (for store) IorD set to 1 Arithmetic-logical (R-type) Action taken Reg [IR [15:11]] <= ALUOut; Control signals required MemtoReg set to 0 RegWrite asserted 34

Breaking Instructions 5. Memory read completion Load Action taken Reg [IR[20:16]] <= MDR; Control signals required MemtoReg set to 1 (to write result from memory) RegWrite asserted (to cause a write) RegDst set to 0 (to choose rt bits 20:16) 35

Finite State Machine Can be used to specify multi-cycle control A sequential logic function consisting of A set of inputs A set of outputs A next state function that maps the current state and the input to a new state An output function that maps the current state and the inputs to a set of asserted outputs 36

Finite State Machine The high-level view of the finite state machine control 37

Finite State Machine Instruction fetch and decode portion of every instruction is identical 38

Finite State Machine Controlling memory reference instructions 39

Finite State Machine R-type instructions 40

Finite State Machine Branch instructions 41

Finite State Machine Jump instructions 42

Finite State Machine Finite state machine controllers are typically implemented using combinational logic ad a register to hold current state 43

Finite State Machine Complete finite state machine control for the datapath 44

Review: Actions of 1- Bit Control Signals Signal name Effect when deasserted Effect when asserted RegSDt RegWrite The register file destination number for the Write register comes from the rt field None The register file destination number for the Write register comes from the rd file The general purpose register selected by the Write register number is written with the value of the Write data input ALUSrcA The first ALU operand is the PC The first ALU operand comes from the A register MemRead None Content of memory at location specified by the Address input is replaced by value on Write data input MemWrite None Memory contents at the location specified by the Address input is replaced by value on Write data input MemToReg The value fed to the register file Write data input comes from ALUOut The value fed to the register file Write data input comes from MDR IorD The PC is used to supply the address to the memory unit ALUOut is used to supply the address to the memory unit IRWrite None The output of the memory is written into IR PCWrite None The PC is written; the source is controlled by PCSource PCWriteCond None The PC is written if the Zero output from the ALU is also active

Review: Actions of 2- Bit Control Signals Signal name Value (Binary) ALUOp ALUSRrcB PCSrc 00 The ALU performs an add operation 01 The ALU performs a subtract operation Effect 10 The funct field of the instruction determines the AKLU operation 00 The second input to the ALU comes from the B register 01 The second input to the ALU is the constant 4 10 The second input to the ALU is the sign-extende, lower 16 bits of the IR 11 The second input to the ALU is the sign-extended, lower 16 bits of the IR shifted left 2 bits 00 Output of the ALU (PC+4) is sent to the PC for writing 01 The contents of the ALUOut (the branch target address) are sent to the PC for writing 10 (PC+4[31:28]) is sent to the PC for writing

Alternatives of Designing & Implementing Control Initial representation Control may be designed using one of several initial representations Sequencing Control The choice of sequence control, and how logic is represented, can then be determined independently Logic Representation Implementation Technique Control can then be implemented with one of several methods using a structured logic technique Finite State Diagram Explicit next state Function Logic equations PLA hardwired control Microprogram Microprogram counter + dispatch ROMs Truth tables ROM micro-programmed control

Macroinstruction Interpretation Main Memory execution unit ADD SUB AND DATA... User program plus Data this can change! one of these is mapped into one of these CPU control memory AND micro-sequence e.g., Fetch Calc Operand Addr Fetch Operand(s) Calculate Save Answer(s)

Multiprogramming & Microinstructions Can we design the control graphically? Full MIPS instruction set contains > 100 instructions An instruction can take (1-20) clock cycle Control function is complex Control unit might need > 1000 s states & 100 s different sequences Specifying the control with graphical representation is very cumbersome & difficult to understand Solution: Use some ideas of programming to make it easier to understand

Terminology Microprogramming: Designing the control as a program that implements machine instructions in terms of simpler microinstructions Microinstruction: A set of datapath signals that must be asserted in a given state Usually stored in ROM or PLA (Appendixes B &C) Has memory addresses Executing a microinstruction: Asserting the control signals specified by the microinstruction

Terminology Inconsistent microinstruction If the instruction requires that a given control signal be set to 2 different values Microinstructions are assumed to be executed sequentially, except for branching Subroutines in microcode: Idea is also incorporated in microprogramming. Microcode could be reused Microcode control units that are used to implement complex microprograms often provide support for microcode subroutines

Designing a Microinstruction Set 1. Start with list of control signals 2. Group signals together that make sense (vs. random), called fields 3. Place fields in some logical order (e.g., ALU operation & ALU operands first and microinstruction sequencing last) 4. Create a symbolic legend for the microinstruction format, showing name of field values and how they set the control signals Use computers to design computers 5. To minimize the width, encode operations that will never be used at the same time

ALU control: Fields of Microinstruction Specify the operation being done by the ALU during this clock; the result is always written in ALUOut SRC1: Specify the source for the first ALU operand SRC2: Specify the source for the second ALU operand Register control: Specify the read or write for the register file, and the source of the value for the write Memory: Specify the read or write, and the source for the memory. For a read, specify the destination register PCWrite control: Specify the writing for the PC Sequencing: Specify how to choose the next microinstruction to be executed

Format of Microinstructions Should simplify the representation (easy to write & understand) Requirements: A field to control the ALU 3 fields to determine the ALU s source & destination registers Should prevent writing inconsistent microinstructions Could be achieved by specifying non-overlapping set of control signals Signals that that are never asserted simultaneously, can share the same field Micro-assemblers check consistency of microcode

Possible Next Microinstruction 1. Sequential: Increment address of current microinstruction Put Seq in sequencing field 2. Branch: Begin execution of next MIPS instruction (initial microinstruction = state(0)) Put Fetch in sequencing field 3. Dispatch: Next microinstruction based on control unit input Creates a table (Dispatch table) containing the address of target microinstruction Usually there are more than one dispatch table Put Dispatch i in sequencing field, where i is the dispatch table number

Format of Microinstructions Field name Value Signals active Comment Label Any string Add ALUOp = 00 Cause the ALU to add. Used to specify labels to control microcode sequencing. Labels that ends with 1 or 2 are used for dispatching with a jump table that is indexed based on the opcode Other labels are used as direct target in microinstruction sequencing Labels don't generate control signalsdirectly but are used to define contents of dispatch tables and generate control for the Sequencing field ALU control Subt ALUOp = 01 Cause the ALU to subtract; this implements the compare for branches. Func code ALUOp = 10 Use the instruction's function code to determine ALU control. SRC1 PC ALUSrcA = 0 Use the PC as the first ALU input. A ALUSrcA = 1 Register A is the first ALU input. B ALUSrcB = 00 Register B is the second ALU input. SRC2 4 ALUSrcB = 01 Use 4 as the second ALU input. Extend ALUSrcB = 10 Use output of the sign extension unit as the second ALU input. Extshft ALUSrcB = 11 Use the output of the shift-by-two unit as the second ALU input. Read Read two registers using the rs and rt fields of the IR as the register numbers and putting the data into registers A and B. Write ALU RegWrite, Write a register using the rd field of the IR as the register number and Register RegDst = 1, the contents of the ALUOut as the data. control MemtoReg = 0 Write MDR RegWrite, Write a register using the rt field of the IR as the register number and RegDst = 0, MemtoReg = 1 the contents of the MDR as the data. Read PC MemRead, Read memory using the PC as address; write result into IR (and lord = 0 the MDR). Memory Read ALU MemRead, Read memory using the ALUOut as address; write result into MDR. lord = 1 Write ALU MemWrite, Write memory using the ALUOut as address, contents of B as the lord = 1 data. ALU PCSource = 00 Write the output of the ALU into the PC. PCWrite PC write control ALUOut-cond PCSource = 01, If the Zero output of the ALU is active, write the PC with the contents PCWriteCond of the register ALUOut. jump address PCSource = 10, Write the PC with the jump address from the instruction. PCWrite Seq AddrCtl = 11 Choose the next microinstruction sequentially. Sequencing Fetch AddrCtl = 00 Go to the first microinstruction to begin a new instruction. Dispatch 1 AddrCtl = 01 Dispatch using the ROM 1. Dispatch 2 AddrCtl = 10 Dispatch using the ROM 2.

Fetch, Decode, & Increment PC Microinstructions needed Microinstruction number ALU Label Control SRC1 SRC2 Register control Memory PCWrite control Sequencing 1 Fetch Add PC 4 Read PC ALU Seq 2 Add PC ExtShft Read Dispatch 1 1st microinstruction Fields 2nd microinstruction Effect ALU control, SRC1, SRC2 Compute PC + 4. (The value is also written into ALUOut though it will never be read from there.) Memory Fetch instruction into IR PCWrite control Causes the output of the ALU to be written into the pc Sequencing Go to the next microinstruction Fields Effect ALU control, SRC1, SRC2 Store PC + sign extension(ir[15:0]) << 2 into ALUOut Use the rs & rt fields to read the registers placing Register control the data in A and B Use dispatch table 1 to choose the next Sequencing microinstruction address

Memory Reference Instructions Microinstructions needed Microinstruction number ALU Label Control SRC1 SRC2 Register control Memory PCWrite control Sequencing 1 Mem1 Add A Extend Dispatch 2 2-a-1 Lw2 Read ALU Seq 2-a-2 Write MDR Fetch 2-b Sw2 Write ALU Fetch Mem1 Lw2-a-1 Fields Effect ALU control, SRC1, SRC2 Compute the memory address: Register(rs) + signextend (IR[15:0]), writing the result into ALUOut Sequencing Use dispatch table 2 to jump to the microinstruction labeled either LW2 or SW2 Fields Memory Sequencing Effect Read memory using the ALUOut as the address and writing the data into MDR Go to the next microinstruction LW2-a-2 Fields Register control Sequencing Effect Write the contents of the MDR into the register file entry specified by rt Go to the microinstruction labeled "Fetch" SW2 Fields Memory Sequencing Effect Write memory using contents of ALUOut as the address and the contents of B as the value Go to the microinstruction labeled "Fetch"

R-Type Instructions Microinstructions needed Microinstruction number Label ALU Control SRC1 SRC2 Register control Memory PCWrite control Sequencing 1 RFormat 1 Func code A B Seq 2 Write ALU Fetch 1st Instruction 2nd Instruction Fields ALU control, SRC1, SRc2 Sequencing Effect Thte ALU operates on the contents of the A and B registers, using the function field to specify the ALU operation Go to the next microinstruction Fields Register control Sequencing Effect The value in ALUOut is written into the register file entry specified by the rd field Go to the microinstruction labeled "Fetch"

Beq Instructions Microinstructions needed Microinstruction number Label ALU Control SRC1 SRC2 Register control Memory PCWrite control Sequencing 1 BEQ1 Subt A B ALUOut-cond Fetch Fields ALU control,src1, SRC2 PCWrite control Sequencing Effect The ALU subtracts the operands in A and B to generate Causes the the PC Zero to outoput be written using the value already in ALUOut, if Zero output of the ALU is true Go to the microinstruction labeled "Fetch"

Jump Instructions Microinstructions needed Microinstruction number Label ALU Control SRC1 SRC2 Register control Memory PCWrite control Sequencing 1 JUMP1 Jump address Fetch Fields PCWrite control Sequencing Effect Causes the PC to be written using the jump target address Go to the microinstruction labeled "Fetch"

Complete Microprogram Label ALU control SRC1 SRC2 Register control Memory PCWrite control Fetch Add PC 4 Read PC ALU Seq Sequencing Add PC Extshft Read Dispatch 1 Mem1 Add A Extend Dispatch 2 LW2 Read ALU Seq Write MDR Fetch SW2 Write ALU Fetch Rformat1 Func code A B Seq Write ALU Fetch BEQ1 Subt A B ALUOut-cond Fetch JUMP1 Jump address Fetch

Implementing Microprogram Micro-programs can be implemented exactly like state machines: PLA ROM Program assembled & stored in microcode storage and is addressed by microprogram counter

O p [ 5 0 ] Implementing Microprogram C o n t r o l u n i t M i c r o c o d e m e m o r y I n p u t O u t p u t s P C W r i t e P C W r i t e C o n d I o r D M e m R e a d M e m W r i t e I R W r i t e B W r i t e M e m t o R e g P C S o u r c e A L U O p A L U S r c B A L U S r c A R e g W r i t e R e g D s t A d d r C t l Datapath 1 A d d e r M i c r o p r o g r a m c o u n t e r A d d r e s s s e l e c t l o g i c Instruction register Opcode field

Microprogramming Pros &Cons Pros: Ease of design Flexibility Easy to adapt to changes in organization, timing, technology Can make changes late in design cycle, or even in the field Can implement very powerful instruction sets (just more control memory) Generality Can implement multiple instruction sets on same machine. Can tailor instruction set to application. Compatibility Many organizations, same instruction set Cons: Costly to implement Slow

Homework Assignment What is the meaning of: Control word Micro instruction Micro-program Compare between: Hardwired Control Micro-program Control 66