Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania 18042 ECE 313 - Computer Organization Lecture 13 - A Verilog.

Slides:



Advertisements
Similar presentations
Pipeline Example: cycle 1 lw R10,9(R1) sub R11,R2, R3 and R12,R4, R5 or R13,R6, R7.
Advertisements

COMP541 Datapath & Single-Cycle MIPS
©UCB CS 161Computer Architecture Chapter 5 Lecture 9 Instructor: L.N. Bhuyan Adapted from notes by Dave Patterson (http.cs.berkeley.edu/~patterson)
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 11 - Processor.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Pipelined Processor.
The Processor: Datapath & Control
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 14 - Multi-Cycle.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 18 - Pipelined.
Processor II CPSC 321 Andreas Klappenecker. Midterm 1 Tuesday, October 5 Thursday, October 7 Advantage: less material Disadvantage: less preparation time.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
Copyright 1998 Morgan Kaufmann Publishers, Inc. All rights reserved. Digital Architectures1 Machine instructions execution steps (1) FETCH = Read the instruction.
The Datapath Andreas Klappenecker CPSC321 Computer Architecture.
©UCB CS 161Computer Architecture Chapter 5 Instructor: L.N. Bhuyan LECTURE 10.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Multi-Cycle Processor.
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
COMP541 Datapaths II & Single-Cycle MIPS
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 15 - Multi-Cycle.
Computer Architecture and Design – ECEN 350 Part 6 [Some slides adapted from A. Sprintson, M. Irwin, D. Paterson and others]
1 COMP541 Datapaths II & Control I Montek Singh Mar 22, 2010.
MIPS processor continued. In Class Exercise Question Show the datapath of a processor that supports only R-type and jr reg instructions.
A Simplified MIPS Processor in Verilog
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 12 - Introduction.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 16 - Multi-Cycle.
PC Instruction Memory Address Instr. [31-0] 4 Fig 4.6 p 309 Instruction Fetch.
A Simplified MIPS Processor in Verilog. Data Memory module DM(MemRead, MemWrite, ABUS, DIN, DATABUS); – MemWrite: Nothing happens if 0. If 1, the memory.
MIPS processor continued
Datapath and Control AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data.
Lecture 9. MIPS Processor Design – Single-Cycle Processor Design Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
Lecture 5. MIPS Processor Design
Computer Architecture Lecture 6.  Our implementation of the MIPS is simplified memory-reference instructions: lw, sw arithmetic-logical instructions:
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 9: MIPS Lite 4 th edition: Chapter.
ECE/CS 552: Single Cycle Control Path
Single-cycle CPU Control
Access the Instruction from Memory
EE204 Computer Architecture
CS Computer Architecture Week 10: Single Cycle Implementation
MIPS Microarchitecture Single-Cycle Processor Control
Single Cycle CPU - Control
CS 230: Computer Organization and Assembly Language
Single-Cycle Datapath and Control
Computer Architecture
/ Computer Architecture and Design
Discussion Session Week 10
MIPS processor continued
CS/COE0447 Computer Organization & Assembly Language
Single-Cycle CPU DataPath.
CS/COE0447 Computer Organization & Assembly Language
CSCI206 - Computer Organization & Programming
Systems Architecture II
Datapath & Control MIPS
Topic 5: Processor Architecture Implementation Methodology
Rocky K. C. Chang 6 November 2017
Composing the Elements
Composing the Elements
The Processor Lecture 3.2: Building a Datapath with Control
Topic 5: Processor Architecture
Lecture 9. MIPS Processor Design – Decoding and Execution
Systems Architecture I
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Lecture 14: Single Cycle MIPS Processor
Single Cycle Datapath Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Foundations for Datapath Design
MIPS processor continued
CS/COE0447 Computer Organization & Assembly Language
Control Unit (single cycle implementation)
The Processor: Datapath & Control.
COMS 361 Computer Organization
Processor: Datapath and Control
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 13 - A Verilog Single-Cycle MIPS Fall 2006 Assignment: Project 2 Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann Publishers all rights reserved Tod Amon's COD2e Slides © 1998 Morgan Kaufmann Publishers all rights reserved Dave Patterson’s CS 152 Slides - Fall 1997 © UCB Rob Rutenbar’s Slides - Fall 1999 CMU other sources as noted

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle2 Outline - A Single-Cycle MIPS in Verilog  Modeling basic datapath components   Modeling the datapath  Modeling the control unit

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle3 Single-Cycle Datapath Components  32-bit adder add32  32-bit ALU alu32  Parameterized 2-1 Multiplexer mux2  32-bit Simple Register reg32  32-bit Idealized Read/Write Memory mem32  32-bit MIPS-Style Register File reg_file  32-bit Idealized Read-Only Memory rom32  ALU Control Unit alu_ctl  Control Unit control_single

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle4 32-Bit Adder // Behavioral model of a 32-bit adder module add32(a, b, result); input [31:0] a, b; output [31:0] result; assign result = a + b; endmodule Adder

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle5 32-Bit ALU module alu(ctl, a, b, result, zero); input[2:0]ctl; input[31:0]a, b; output[31:0]result; outputzero; reg [31:0]result; reg zero; or b or ctl) begin case (ctl) 3'b000 : result = a & b; // AND 3'b001 : result = a | b; // OR 3'b010 : result = a + b; // ADD 3'b110 : result = a - b; // SUBTRACT 3'b111 : if (a < b) result = 32'd1; else result = 32'd0; //SLT default : result = 32'hxxxxxxxx; endcase if (result == 32'd0) zero = 1; else zero = 0; end endmodule ALU zero

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle6 2-1 Multiplexer (Parameterized) module mux2( sel, a, b, y ); parameter bitwidth=32; input sel; input[bitwidth-1:0]a, b; output[bitwidth-1:0]y; assign y = sel ? b : a; endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle7 32-Bit Register (e.g., PC) // Simple 32-bit register module reg32 (clk, reset, d_in, d_out); input clk, reset; input [31:0]d_in; output [31:0] d_out; reg [31:0]d_out; clk) begin if (reset) d_out <= 0; else d_out <= d_in; end endmodule 32 CLK reset Data In Data Out REG

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle8 Idealized Memory - Part 1 module mem32(clk, mem_read, mem_write, address, data_in, data_out); input clk, mem_read, mem_write; input [31:0] address, data_in; output [31:0] data_out; reg [31:0] data_out; parameter BASE_ADDRESS = 25'd0; reg [31:0] mem_array [0:31]; wire [4:0] mem_offset; wire address_select; assign mem_offset = address[6:2] assign address_select = (address[31:7] == BASE_ADDRESS); // address decoding

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle9 Idealized Memory - Part 2 or address_select or mem_offset or mem_array[mem_offset]) begin if (mem_read == 1'b1 && address_select == 1'b1) begin if ((address % 4) != 0) $display($time, " rom32 error: unaligned address %d", address); data_out = mem_array[mem_offset]; $display($time, " reading data: Mem[%h] => %h", address, data_out); end else data_out = 32'hxxxxxxxx; end

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle10 Idealized Memory - Part 3 // for WRITE operations clk) begin if (mem_write == 1'b1 && address_select == 1'b1) begin $display($time, " writing data: Mem[%h] <= %h", address,data_in); mem_array[mem_offset] <= data_in; end // initialize with some arbitrary values integer i; initial begin for (i=0; i<7; i=i+1) mem_array[i] = i; end endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle11 Register File module reg_file(clk, RegWrite, RN1, RN2, WN, RD1, RD2, WD); input clk; input RegWrite; input [4:0] RN1, RN2, WN; input [31:0] WD; output [31:0] RD1, RD2; reg [31:0] RD1, RD2; reg [31:0] file_array [31:1];

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle12 Register File - Part 2 or file_array[RN1]) begin if (RN1 == 0) RD1 = 32'd0; else RD1 = file_array[RN1]; $display($time, " reg_file[%d] => %d (Port 1)", RN1, RD1); end or file_array[RN2]) begin if (RN2 == 0) RD2 = 32'd0; else RD2 = file_array[RN2]; $display($time, " reg_file[%d] => %d (Port 2)", RN2, RD2); end clk) if (RegWrite && (WN != 0)) begin file_array[WN] <= WD; $display($time, " reg_file[%d] <= %d (Write)", WN, WD); end endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle13 32-Bit Idealized ROM  Input: 32-bit address  Output: 32-bit data  Use to model instruction memory

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle14 32-bit Idealized ROM - Part 1 // A simple 32-bit by 32-word read-only memory model // ECE 313 Fall 2002 module rom32(address, data_out); input [31:0] address; output [31:0] data_out; reg [31:0] data_out; parameter BASE_ADDRESS = 25'd0; // address that applies to this memory reg [31:0] mem_arrray [0:31]; wire [4:0] mem_offset; wire address_select; assign mem_offset = address[6:2]; // to get word offset // address decoding assign address_select = (address[31:7] == BASE_ADDRESS);

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle15 32-bit Idealized ROM - Part 2 or mem_offset) begin if ((address % 4) != 0) $display($time, " rom32 error: unaligned address %d", address); if (address_select == 1) begin case (mem_offset) 5'd0 : data_out = { 6'd35, 5'd0, 5'd2, 16'd4 }; 5'd1 : data_out = { 6'd35, 5'd0, 5'd3, 16'd8 }; 5'd2 : data_out = { 6'd35, 5'd0, 5'd4, 16'd20 }; 5'd3 : data_out = { 6'd0, 5'd0, 5'd0, 5'd5, 5'd0, 6'd32 }; 5'd4 : data_out = { 6'd0, 5'd5, 5'd2, 5'd5, 5'd0, 6'd32 }; 5'd5 : data_out = { 6'd0, 5'd4, 5'd5, 5'd6, 5'd0, 6'd42 }; 5'd6 : data_out = { 6'd4, 5'd6, 5'd0, -16'd3 }; 5'd7 : data_out = { 6'd43, 5'd0, 5'd5, 16'd0 }; default data_out = 32'hxxxx; endcase $display($time, " reading data: rom32[%h] => %h", address, data_out); end endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle16 32-bit Idealized ROM - case case (mem_offset) 5'd0 : data_out = { 6'd35, 5'd0, 5'd2, 16'd4 }; // lw $2, 4($0) r2=1 5'd1 : data_out = { 6'd35, 5'd0, 5'd3, 16'd8 }; // lw $3, 8($0) r3=2 5'd2 : data_out = { 6'd35, 5'd0, 5'd4, 16'd20 }; // lw $4, 20($0) r4=5 5'd3 : data_out = { 6'd0, 5'd0, 5'd0, 5'd5, 5'd0, 6'd32 }; // add $5, $0, $0 r5=0 5'd4 : data_out = { 6'd0, 5'd5, 5'd2, 5'd5, 5'd0, 6'd32 }; // add $5, $5, $1 r5 = r 'd5 : data_out = { 6'd0, 5'd4, 5'd5, 5'd6, 5'd0, 6'd42 }; // slt $6, $4, $5 is r5 >= 5? 5'd6 : data_out = { 6'd4, 5'd6, 5'd0, -16'd3 }; // beq $6, $zero, -3 if not, go back 2 5'd7 : data_out = { 6'd43, 5'd0, 5'd5, 16'd0 }; // s2 $6, 0($zero) MEM[0] = $5 // add more cases here as desired default data_out = 32'hxxxx; endcase

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle17 ALU Control  Review - ALU Control Function OperationDesired Action lwadd swadd beqsubtract add subsubtract and or slt and or set on less than ALU Ctl funct XXXXXX Instr. type data transfer branch r-type ALUOp

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle18 ALU Control Unit - Part 1 module alu_ctl(ALUOp, Funct, ALUOperation); input [1:0] ALUOp; input [5:0] Funct; output [2:0] ALUOperation; reg [2:0] ALUOperation; // symbolic constants for instruction function code parameter F_add = 6'd32; parameter F_sub = 6'd34; parameter F_and = 6'd36; parameter F_or = 6'd37; parameter F_slt = 6'd42; // symbolic constants for ALU Operations parameter ALU_add = 3'b010; parameter ALU_sub = 3'b110; parameter ALU_and = 3'b000; parameter ALU_or = 3'b001; parameter ALU_slt = 3'b111; Symbolic Constants - MIPS Function Codes Symbolic Constants - ALU Operations

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle19 ALU Control Unit - Part 2 or Funct) begin case (ALUOp) 2'b00 : ALUOperation = ALU_add; 2'b01 : ALUOperation = ALU_sub; 2'b10 : case (Funct) F_add : ALUOperation = ALU_add; F_sub : ALUOperation = ALU_sub; F_and : ALUOperation = ALU_and; F_or : ALUOperation = ALU_or; F_slt : ALUOperation = ALU_slt; default : ALUOperation = 3'bxxx; endcase default ALUOperation = 3'bxxx; endcase end endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle20 Main Control Unit  Review - Control Unit Function Op5Op4Op3Op2Op1Op0 RegDstALUSrcMemtoRegRegWriteMemReadMemWriteBranchALUOp1ALUOp X1X X0X OP RT lw sw beq InputOutput

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle21 Single-Cycle Control Unit - Part 1 module control_single(opcode, RegDst, ALUSrc, MemtoReg, RegWrite, MemRead, MemWrite, Branch, ALUOp); input [5:0] opcode; output RegDst, ALUSrc, MemtoReg, RegWrite, MemRead, MemWrite, Branch; output [1:0] ALUOp; reg RegDst, ALUSrc, MemtoReg, RegWrite, MemRead, MemWrite, Branch; reg [1:0] ALUOp; parameter R_FORMAT = 6'd0; parameter LW = 6'd35; parameter SW = 6'd43; parameter BEQ = 6'd4;

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle22 Single-Cycle Control Unit - Part 2 begin case (opcode) R_FORMAT : begin RegDst=1'b1; ALUSrc=1'b0; MemtoReg=1'b0; RegWrite=1'b1; MemRead=1'b0; MemWrite=1'b0; Branch=1'b0; ALUOp = 2'b10; end LW : begin RegDst=1'b0; ALUSrc=1'b1; MemtoReg=1'b1; RegWrite=1'b1; MemRead=1'b1; MemWrite=1'b0; Branch=1'b0; ALUOp = 2'b00; end SW : begin RegDst=1'bx; ALUSrc=1'b1; MemtoReg=1'bx; RegWrite=1'b0; MemRead=1'b0; MemWrite=1'b1; Branch=1'b0; ALUOp = 2'b00; end

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle23 Single-Cycle Control Unit - Part 3 case (opcode) BEQ : begin RegDst=1'bx; ALUSrc=1'b0; MemtoReg=1'bx; RegWrite=1'b0; MemRead=1'b0; MemWrite=1'b0; Branch=1'b1; ALUOp = 2'b01; end default : begin $display("control_single unimplemented opcode %d", opcode); RegDst=1'bx; ALUSrc=1'bx; MemtoReg=1'bx; RegWrite=1'bx; MemRead=1'bx; MemWrite=1'bx; Branch=1'bx; ALUOp = 2'bxx; end endcase end endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle24 Single-Cycle Processor - Wires

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle25 Single-Cycle Verilog - Part 1 module mips_single(clk, reset); input clk, reset; // instruction bus wire [31:0] instr; // break out important fields from instruction wire [5:0] opcode, funct; wire [4:0] rs, rt, rd, shamt; wire [15:0] immed; wire [31:0] extend_immed, b_offset; wire [25:0] jumpoffset; assign opcode = instr[31:26]; assign rs = instr[25:21]; assign rt = instr[20:16]; assign rd = instr[15:11]; assign shamt = instr[10:6]; assign funct = instr[5:0]; assign immed = instr[15:0]; assign jumpoffset = instr[25:0];

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle26 Single-Cycle Verilog - Part 2 // sign-extender assign extend_immed = { {16{immed[15]}}, immed }; // branch offset shifter assign b_offset = extend_immed << 2; // datapath signals wire [4:0] rfile_wn; wire [31:0] rfile_rd1, rfile_rd2, rfile_wd, alu_b, alu_out, b_tgt, pc_next, pc, pc_incr, br_add_out, dmem_rdata; // control signals wire RegWrite, Branch, PCSrc, RegDst, MemtoReg, MemRead, MemWrite, ALUSrc, Zero; wire [1:0] ALUOp; wire [2:0] Operation;

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle27 Single-Cycle Verilog - Part 3 // module instantiations reg32PC(clk, reset, pc_next, pc); add32 PCADD(pc, 32'd4, pc_incr); add32 BRADD(pc_incr, b_offset, b_tgt); reg_fileRFILE(clk, RegWrite, rs, rt, rfile_wn, rfile_rd1, rfile_rd2, rfile_wd); alu ALU(Operation, rfile_rd1, alu_b, alu_out, Zero); rom32 IMEM(pc, instr); mem32 DMEM(clk, MemRead, MemWrite, alu_out, rfile_rd2, dmem_rdata); andBR_AND(PCSrc, Branch, Zero);

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle28 Single-Cycle Verilog - Part 4 mux2 #(5)RFMUX(RegDst, rt, rd, rfile_wn); mux2 #(32)PCMUX(PCSrc, pc_incr, b_tgt, pc_next); mux2 #(32)ALUMUX(ALUSrc, rfile_rd2, extend_immed, alu_b); mux2 #(32)WRMUX(MemtoReg, alu_out, dmem_rdata, rfile_wd); control_single CTL(.opcode(opcode),.RegDst(RegDst),.ALUSrc(ALUSrc),.MemtoReg(MemtoReg),.RegWrite(RegWrite),.MemRead(MemRead),.MemWrite(MemWrite),.Branch(Branch),.ALUOp(ALUOp)); alu_ctl ALUCTL(ALUOp, funct, Operation); endmodule

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle29 Project 2 - Extending the SC MIPS Model  Download files from Website  Simulate to gain familiarity with operation  Modify the design to support:  addi rd, rs, rt  bne rs, rt ( in addition to beq )  j addr  Modify ROM to contain a test program  Write short assembly language to test all instructions  Include a loop that executes at least 4 times  Hand-assemble or assemble with SPIM  Modify ROM code

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle30 Demo: Simulating mips_single  ROM Contains the following program lw $2, 4($0) # r2=1 lw $3, 8($0) # r3=2 lw $4, 20($0) # r4=5 add $5, $0, $0 # r5=0 add $5, $5, $1 # r5 = r5 + 1 slt $6, $4, $5 # is $5 >= r4? beq $6, $zero, -3 # if not, go back 2 sw $6, 0($zero) # MEM[0] = $5  Connections to watch:  PC, Instruction  Instruction fields: opcode, rs, rt, rd, immed, etc.  Register file: rfile_wn, regfile_rd1, regfile_rd2  ALU: alu_b, alu_out, Zero

ECE 313 Fall 2006Lecture 13 - Verilog Single-Cycle31 Coming Up  Multicycle Processor Design  Overview  Datapath Design  Controller Design  Microprogramming  Exceptions  Performance Considerations