Lecture 9. MIPS Processor Design – Decoding and Execution

Slides:



Advertisements
Similar presentations
Computer Science Education
Advertisements

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 13 - A Verilog.
COMP541 Datapath & Single-Cycle MIPS
The Processor: Datapath & Control
Levels in Processor Design
The Processor 2 Andreas Klappenecker CPSC321 Computer Architecture.
Copyright 1998 Morgan Kaufmann Publishers, Inc. All rights reserved. Digital Architectures1 Machine instructions execution steps (1) FETCH = Read the instruction.
The Processor: Datapath & Control. Implementing Instructions Simplified instruction set memory-reference instructions: lw, sw arithmetic-logical instructions:
ECM534 Advanced Computer Architecture Lecture 5. MIPS Processor Design
COSC 3430 L08 Basic MIPS Architecture.1 COSC 3430 Computer Architecture Lecture 08 Processors Single cycle Datapath PH 3: Sections
Lecture 9. MIPS Processor Design – Instruction Fetch Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education &
COMP541 Datapaths II & Single-Cycle MIPS
CS2100 Computer Organisation The Processor: Datapath (AY2015/6) Semester 1.
Computer Architecture and Design – ECEN 350 Part 6 [Some slides adapted from A. Sprintson, M. Irwin, D. Paterson and others]
1 A single-cycle MIPS processor  An instruction set architecture is an interface that defines the hardware operations which are available to software.
1 COMP541 Datapaths II & Control I Montek Singh Mar 22, 2010.
Another Example: MIPS From the Harris/Weste book Based on the MIPS-like processor from the Hennessy/Patterson book.
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
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.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
MIPS Processor.
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:
Single-cycle CPU Control
Access the Instruction from Memory
EE204 Computer Architecture
Single Cycle CPU - Control
Microarchitecture.
CS161 – Design and Architecture of Computer Systems
CS 230: Computer Organization and Assembly Language
Single-Cycle Datapath and Control
Computer Architecture
IT 251 Computer Organization and Architecture
Morgan Kaufmann Publishers
Multi-Cycle CPU.
MIPS Processor.
CS/COE0447 Computer Organization & Assembly Language
MIPS processor continued
Single Cycle CPU Design
CSCI206 - Computer Organization & Programming
A Simplified MIPS Processor in Verilog
CS/COE0447 Computer Organization & Assembly Language
Single-Cycle CPU DataPath.
CS/COE0447 Computer Organization & Assembly Language
CSCI206 - Computer Organization & Programming
MIPS Processor.
Datapath & Control MIPS
Levels in Processor Design
The Single Cycle Datapath
Rocky K. C. Chang 6 November 2017
The Processor Lecture 3.2: Building a Datapath with Control
Topic 5: Processor Architecture
COMS 361 Computer Organization
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.
Computer Architecture Processor: Datapath
MIPS processor continued
CS/COE0447 Computer Organization & Assembly Language
The Processor: Datapath & Control.
COMS 361 Computer Organization
Designing a Single-Cycle Processor
MIPS Processor.
Processor: Datapath and Control
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

Lecture 9. MIPS Processor Design – Decoding and Execution 2010 R&E Computer System Education & Research Lecture 9. MIPS Processor Design – Decoding and Execution Prof. Taeweon Suh Computer Science Education Korea University

Data in your program, Stack, Heap Instruction Memory MIPS CPU Address Bus Data Bus Data Overview of CPU Design mips_tb.v (testbench) mips_cpu_mem.v reset mips_cpu.v imem.v (Instruction Memory) Address Decoding fetch, pc clock Binary (machine code) Instruction Register File ALU Memory Access dmem.v (Data Memory) Address DataOut Data in your program, Stack, Heap DataIn

Increment by 4 for next instruction 32-bit register (flip-flops) Instruction Fetch MIPS CPU Core Increment by 4 for next instruction 4 Add Instruction Memory Address Out 32 PC reset clock instruction 32-bit register (flip-flops) What is PC on reset? MIPS initializes the PC to 0xBFC0_0000 For the sake of simplicity, let’s initialize the PC to 0x0000_0000 in our design How about x86 and ARM? x86 reset vector is 0xFFFF_FFF0. BIOS ROM is located there ARM reset vector is 0x0000_0000

Instruction Decoding Instruction Decoding Separate the fetched instruction into the fields (according to the instruction types: R, I, and J types) Opcode and funct fields determine which operation the instruction wants to do Control logic needs to be designed to supply control signals to appropriate components (such as ALU and register file) inside CPU Operands Register addresses in the instruction are sent to the register file Immediate field is either sign-extended or zero-extended depending on the instruction

Instruction Decoding Schematic MIPS CPU Core Control Unit Opcode funct RegWrite Register File wa[4:0] ra1[4:0] ra2[4:0] rd1 32 rd2 wd RegWrite R0 R1 R2 R3 R30 R31 … instruction PC Add 4 reset clock Instruction Memory Address Out 16 32 Sign or zero-extended imm 32

Register File in Verilog module regfile(input clk, input RegWrite, input [4:0] ra1, ra2, wa, input [31:0] wd, output [31:0] rd1, rd2); reg [31:0] rf[31:0]; // three ported register file // read two ports combinationally // write third port on rising edge of clock // register 0 hardwired to 0 always @(posedge clk) if (RegWrite) rf[wa] <= wd; assign rd1 = (ra1 != 0) ? rf[ra1] : 0; assign rd2 = (ra2 != 0) ? rf[ra2] : 0; endmodule Register File wa ra1[4:0] ra2[4:0] 32 bits rd1 32 5 rd2 wd RegWrite R0 R1 R2 R3 R30 R31 …

Sign/Zero Extension in Verilog Why declares it as reg? Is it going to be synthesized as registers? Is this logic combinational or sequential logic? module sign_zero_ext(input sign_ext, input [15:0] a, output reg [31:0] y); always @(*) begin if (sign_ext) y <= {{16{a[15]}}, a}; else y <= {{16{1'b0}}, a}; end endmodule 16 32 Sign or zero-extended a[15:0] = imm y[31:0] sign_ext

Instruction Execution #1 Execution of the arithmetic and logical instructions R-type arithmetic and logical instructions Examples: add, sub, and, or ... Operand sources 2 Operands from the register file I-type arithmetic and logical instructions Examples: addi, andi, ori ... 1 operand from the register file 1 operand from the immediate field opcode rs rt rd sa funct add $t0, $s1, $s2 destination register opcode rs rt immediate addi $t0, $s3, -12

Instruction Execution Schematic – Arithmetic and Logical Instructions MIPS CPU Core Control Unit Opcode funct ALUSrc RegWrite Register File wa[4:0] ra1[4:0] ra2[4:0] rd1 32 rd2 wd RegWrite R0 R1 R2 R3 R30 R31 … ALU ALUSrc instruction mux PC Add 4 reset clock Instruction Memory Address Out 16 32 Sign or zero-extended imm 32

How to Design Mux in Verilog? module mux2 (input [31:0] d0, d1, input s, output [31:0] y); assign y = s ? d1 : d0; endmodule module mux2 (input [31:0] d0, d1, input s, output reg [31:0] y); always @(*) begin if (s) y <= d1; else y <= d0; end endmodule OR Design it with parameter, so that this module can be used (instantiatiated) in any sized muxes in your design module datapath(………); wire [31:0] writedata, signimm; wire [31:0] srcb; wire alusrc // Instantiation mux2 #(32) srcbmux(writedata, signimm, alusrc, srcb); endmodule module mux2 #(parameter WIDTH = 8) (input [WIDTH-1:0] d0, d1, input s, output [WIDTH-1:0] y); assign y = s ? d1 : d0; endmodule

Instruction Execution #2 Execution of the memory access instructions lw, sw instructions opcode rs rt immediate lw $t0, 24($s3) // $t0 <= [$s3 + 24] opcode rs rt immediate sw $t2, 8($s3) // [$s3 + 8] <= $t2

Instruction Execution Schematic with Memory Access Instructions MIPS CPU Core Control Unit Opcode funct MemtoReg MemWrite Data Memory Address ReadData WriteData MemWrite ALUSrc RegWrite Register File wa[4:0] ra1[4:0] ra2[4:0] rd1 32 rd2 wd R0 R1 R2 R3 R30 R31 … ALU ALUSrc instruction mux MemtoReg mux PC Add 4 reset clock Instruction Memory Address Out 16 32 Sign or zero-extended imm 32 lw $t0, 24($s3) // $t0 <= [$s3 + 24] sw $t2, 8($s3) // [$s3 + 8] <= $t2

Data Memory Verilog Model module dmem(input clk, MemWrite, input [31:0] Address, input [31:0] WriteData, output [31:0] ReadData); reg [31:0] RAM[63:0]; assign ReadData = RAM[Address[7:2]]; always @(posedge clk) begin if (MemWrite) RAM[Address[7:2]] <= WriteData; end endmodule 32 Data Memory Address ReadData[31:0] WriteDat[31:0] MemWrite 6 64 words Word (32-bit)

Instruction Execution #3 Execution of the branch and jump instructions beq, bne, j, jal, jr instructions opcode rs rt immediate beq $s0, $s1, Lbl // go to Lbl if $s0=$s1 Destination = (PC + 4) + (imm << 2) opcode jump target j target // jump Destination = {PC[31:28] , jump target, 2’b00}

Instruction Execution Schematic with “beq” Instruction MIPS CPU Core Control Unit Opcode funct branch PCSrc zero Data Memory Address ReadData WriteData MemWrite Register File wa[4:0] ra1[4:0] ra2[4:0] rd1 32 rd2 wd R0 R1 R2 R3 R30 R31 … ALU ALUSrc mux MemtoReg instruction mux PCSrc mux Add Instruction Memory Address Out 16 32 Sign or zero-extended imm 4 Add <<2 32 PC reset clock Destination = (PC + 4) + (imm << 2)

Instruction Execution Schematic with “j” Instruction MIPS CPU Core Control Unit Opcode funct jump branch PCSrc zero Data Memory Address ReadData WriteData MemWrite Register File wa[4:0] ra1[4:0] ra2[4:0] rd1 32 rd2 wd R0 R1 R2 R3 R30 R31 … ALU ALUSrc mux MemtoReg instruction mux PCSrc jump mux Add mux 16 32 Sign or zero-extended imm Instruction Memory Address Out <<2 4 Add 26 imm <<2 32 PC 28 J_addr reset clock PC[31:28] Destination = {PC[31:28] , jump target, 2’b00}