SlideShare a Scribd company logo
14
Most read
19
Most read
22
Most read
Designing a Single Cycle MIPS microprocessor in
Verilog
Harsha Yelisala
Spring 2009
Technology Profile
The following technologies are used in this project,
MIPS Processor Architecture.
Verilog HDL.
VHDL HDL.
ModelSim 6.2 SE
Timing Analysis
SPIM
Aim
The Objectives of this project are
1. To design a Single Cycle MIPS Microprocessor in Verilog
and simulate the design in Modelsim.
2. To get hands-on experience in Verilog coding.
3. To get working expertise in using the Modelsim PE
Student Edition 6.6a.
4. To understand the various stages of a processor design.
5. To analyze a processor from timing perspective.
Abstract
Designing a processor is one of the most challenging tasks in chip
designing industry. Being part of processor making is the ultimate
goal of many hardware engineers. Hence a thorough understanding
of working of a processor is of high importance. This project deals
with designing a single cycle microprocessor in Verilog. The design
is then simulated in Modelsim.
Work Flow
1. Studying the data path of a processor from Computer
Organization and Design, The Hardware Software Interface
3rd Edition 2004.
2. Creating Verilog modules for each functional unit of the
datapath.
3. Testing the created modules with customized test benches.
4. Combining the designed modules to a single top module.
5. Verifying and testing the final module in Modelsim.
Datapath
The datapath of a processor has the following functional units.
1. ProgramCounter
2. Register File
3. Arithmetic Logic Unit
4. Instruction Memory
5. Data Memory
6. Adders
7. Multiplexors
8. Shifters
9. SignExtender and
10. Control Unit
Datapath
Control Information
ALU Control Lines Function
0000 AND
0001 OR
0010 ADD
0110 SUB
0111 SLT
1100 NOR
Alu Control Implementation-1 of 2
Opcode AluOp Operation Funct Field Desired ALU Action ALU Control output
LW 00 load word XXXXXX add 0010
SW 00 store word XXXXXX add 0010
BEQ 01 branch equal XXXXXX sub 0110
R-type 10 add 100000 add 0010
R-type 10 sub 100010 sub 0110
R-type 10 and 100100 and 0000
R-type 10 or 100101 or 0001
R-type 10 slt 101010 set lessthan 0111
Alu Control Implementation-2 of 2
AluOp 1 AluOp 0 F5 F4 F3 F2 F1 F0 Operation
0 0 X X X X X X 0010
X 1 X X X X X X 0110
1 X X X 0 0 0 0 0010
1 X X X 0 0 1 0 0110
1 X X X 0 1 0 0 0000
1 X X X 0 1 0 1 0001
1 X X X 1 0 1 0 0111
Control Block Implementation
Control R-Format LW SW BEQ
RegDst 1 0 X X
ALUSrc 0 1 1 0
MemtoReg 0 1 X X
RegWrite 1 1 0 0
MemRead 0 1 0 0
MemWrite 0 0 1 0
Branch 0 0 0 1
AluOp1 1 0 0 0
AluOp 0 0 0 0 1
ProgramCounter
module PC(clock,reset,pcin,pcout);
input clock;
input reset;
input [31:0] pcin;
output [31:0] pcout;
reg clk;
reg [31:0] pcout;
initial
begin
clk=clock;
end
always
#5 clk = ~clk;
always @(posegde(clk))
pcout<=pcin;
endmodule
RegisterFile
module REGISTERS(ReadRegister1,ReadRegister2, WriteRegister, WriteData_reg,RegWrite,ReadData1,ReadData2);
input [4:0] ReadRegister1, ReadRegister2, WriteRegister;
input [31:0] WriteData_reg;
input RegWrite;
output [31:0] ReadData1, ReadData2;
reg [31:0] ReadData1, ReadData2;
reg [31:0] REG[0:31];
integer i;
initial
begin
for(i=0;i<32;i=i+1)
REG[i]=0;
end
always @(ReadRegister1,ReadRegister2,RegWrite,WriteRegister,WriteData_reg)
if(RegWrite==1’b1)
REG[WriteRegister]=WriteData_reg;
else
begin
ReadData1 <= REG[ReadRegister1];
ReadData2 <= REG[ReadRegister2];
end
endmodule
ArithmeticLogicUnit
module ALU(Read_data_1, Read_data_2, ALUControl, ALUresult, isZero);
input [31:0] Read_data_1, Read_data_2;
input [3:0] ALUControl;
output [31:0]ALUresult, isZero;
reg [31:0] ALUresult, isZero;
reg [3:0] addcode, subcode, andcode, orcode, sltcode;
initial begin
addcode[3:0] <= 4’b0010;
subcode[3:0] <= 4’b0110;
andcode[3:0] <= 4’b0000;
orcode[3:0] <= 4’b0001;
sltcode[3:0] <= 4’b0111;
end
always @(Read_data_1, Read_data_2, ALUControl)
if (ALUControl == addcode) //add
ALUresult = Read_data_1 + Read_data_2;
else if(ALUControl == subcode) //sub
ALUresult = Read_data_1 - Read_data_2;
else if(ALUControl == andcode) //and
ALUresult = Read_data_1 & Read_data_2;
else if(ALUControl == orcode) //or
ALUresult = Read_data_1 | Read_data_2;
else if(ALUControl == sltcode) //slt
if(Read_data_1 < Read_data_2)
ALUresult = 32’b00000000000000000000000000000001;
else
ALUresult = 32’b00000000000000000000000000000000;
always @(Read_data_1, Read_data_2, ALUControl,ALUresult)
if(ALUresult == 32’b0)
isZero = 32’b00000000000000000000000000000001;
else
isZero = 32’b00000000000000000000000000000000;
endmodule
InstructionMemory
module INSTRUCTIONMEMORY(ReadAddress,Instruction);
input [31:0] ReadAddress;
output [31:0] Instruction;
reg [31:0] Instruction;
reg [31:0] IMEM[0:64];
integer i;
initial begin
for(i=0;i<64;i=i+1)
IMEM[i]=1’b0;
end
always @(ReadAddress)
Instruction=IMEM[ReadAddress];
endmodule
DataMemory
module DATAMEMORY(Address,MemWrite,MemRead,WriteData,ReadData);
input [31:0] Address;
input MemWrite;
input MemRead;
input [31:0] WriteData;
output [31:0] ReadData;
reg [31:0] ReadData;
reg [31:0] RAM[0:63];
integer i,j;
initial
begin
for(i=0;i<64;i=i+1)
for(j=0;j<32;j=j+1)
RAM[i][j]<=0;
end
always @(Address,MemWrite,MemRead,WriteData)
if(MemWrite==1’b1)
RAM[Address]=WriteData;
else if(MemRead==1’b1)
ReadData=RAM[Address];
endmodule
ControlUnit
module CONTROL(opcode,RegDst,Branch,MemRead,MemtoReg,ALUOp,MemWrite,ALUSrc,RegWrite);
input [6:0] opcode;
output RegDst, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite;
output [1:0] ALUOp;
reg RegDst, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite;
reg [1:0] ALUOp;
always @(opcode)
begin
if(opcode==6’b000000) //r controls
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
if(opcode==6’b100011) //lw controls
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
if(opcode==6’b101011) //sw controls
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
if(opcode==6’b101011) //beq controls
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
end
endmodule
Adders and Multiplexors
module ADD(data1, data2, sum);
input [31:0] data1;
input [31:0] data2;
output [31:0]sum;
reg [31:0]sum;
always @(data1, data2)
sum = data1 + data2;
endmodule
module MUX(mux_in_1,mux_in_2,sel,mux_out);
input [31:0] mux_in_1;
input [31:0] mux_in_2;
input sel;
output [31:0] mux_out;
reg [31:0] mux_out;
always @(mux_in_1,mux_in_2,sel)
if(sel==1’b0)
mux_out=mux_in_1;
else
mux_out=mux_in_2;
endmodule
Shifter and Signextender
module SHIFTLEFT(shift_in,shift_out);
input [31:0] shift_in;
output [31:0] shift_out;
reg [31:0] shift_out;
reg [29:0] temp;
always @(shift_in)
shift_out= shift_in<<2;
endmodule
module SIGNEXTEND(sign_in, sign_out);
input [15:0] sign_in;
output [31:0] sign_out;
reg [31:0] sign_out;
reg [31:0] tmp;
integer i;
initial
begin
sign_out <=32’b0;
end
always @(sign_in)
if(sign_in[15] == 0)
sign_out = {32’b000000000000000000,sign_in};
else
sign_out = {32’b111111111111111111,sign_in};
endmodule
SingleCycleMIPSProcessor
module SINGLECYCLEMIPSPROCESSOR(globalclock,globalreset);
input globalclock;
input globalreset;
wire [31:0] _pcout;
wire [31:0] _Instruction;
wire [31:0] _ReadData1;
wire [31:0] _ReadData2;
wire _RegDst,_Branch,_MemRead,_MemtoReg,_MemWrite,_ALUSrc,_RegWrite;
wire [1:0] _ALUOp;
wire [31:0] _sign_out;
wire [31:0] _shift_out;
wire [31:0] _sum_pcplus4;
wire [31:0] _sum_branchadder;
wire _sel_regfiledest;
wire [31:0] _mux_out_alusrc;
wire _sel_alusrc;
wire [31:0] _mux_out_branchornot;
wire _sel_branchornot;
wire [31:0] #20 _mux_out_regfiledata;
wire [4:0] _mux_out_regfiledest_5b;
wire [3:0] _ALUControl;
wire [31:0] _ReadData;
wire [31:0] _ALUresult;
wire _isZero;
//After Portmapping
PC mypc(.clock(globalclock),.reset(globalreset),.pcin(_mux_out_branchornot),.pcout(_pcout));
INSTRUCTIONMEMORY myinstructionmemory(.ReadAddress(_pcout),.Instruction(_Instruction));
REGISTERS myregisters(.ReadRegister1(_Instruction[25:21]),.ReadRegister2(_Instruction[20:16]),.WriteRegister(_mux_out_regfiledest_5b),.WriteData_reg(_mux_out
CONTROL mycontrol(.opcode(_Instruction[31:26]),.RegDst(_RegDst),.Branch(_Branch),.MemRead(_MemRead),.MemtoReg(_MemtoReg),.ALUOp(_ALUOp),.MemWrite(_MemWrite),
SIGNEXTEND mysignextend( .sign_in(_Instruction[15:0]), .sign_out(_sign_out) );
SHIFTLEFT myshiftleft( .shift_in(_sign_out), .shift_out(_shift_out) );
ADDPLUS4 myadd_pc_plus4(.data1(_pcout), .sum(_sum_pcplus4));
ADD myadd_branchadder(.data1(_sum_pcplus4), .data2(_shift_out), .sum(_sum_branchadder));
MUX5B mymux_regfiledest( .mux_in_1(_Instruction[20:16]), .mux_in_2(_Instruction[15:11]), .sel(_RegDst), .mux_out(_mux_out_regfiledest_5b) );
MUX mymux_alusrc( .mux_in_1(_ReadData2), .mux_in_2(_sign_out), .sel(_ALUSrc), .mux_out(_mux_out_alusrc) );
AND a(_sel_branchornot,Branch,isZero);
MUX mymux_branchornot( .mux_in_1(_sum_pcplus4), .mux_in_2(_sum_branchadder), .sel(_sel_branchornot), .mux_out(_mux_out_branchornot) );
MUX mymux_regfiledata( .mux_in_1(_ReadData), .mux_in_2(_ALUresult), .sel(_MemtoReg), .mux_out(_mux_out_regfiledata) );
ALUCONTROL myalucontrol( .ALUop(_ALUOp), .Funct(_Instruction[5:0]), .ALUControl(_ALUControl) );
DATAMEMORY mydatamemory(.Address(_ALUresult),.MemWrite(_MemWrite),.MemRead(_MemRead),.WriteData(_ReadData2),.ReadData(_ReadData));
ALU myalu( .Read_data_1(_ReadData1), .Read_data_2(_mux_out_alusrc), .ALUControl(_ALUControl), .ALUresult(_ALUresult),.isZero(_isZero) );
endmodule
Pros-Cons
Pros
Simple to design
CPI is always 1.
Cons
It is inefficient.
Every clockcycle must have the same length as the longest
possible path(Load instruction) in the design making the other
instructions which work in lesser cycle time are forced to work
for extra time.
Though the CPI is 1, the overall system performance of the
design is not good.
Conclusion
In this academic project,
A single cycle MIPS microprocessor is designed.
Understood the design flow for the datapath design in a
Processor design.
Experience gained in Verilog coding and debugging.
Experience gained in usage of ModelSim 6.2 SE.
Understood the necessity of Pipelining and other advanced
techniques for processor design.

More Related Content

What's hot (20)

PDF
Verilog Tasks & Functions
anand hd
 
PPT
8255 ppi
Suraj Bora
 
PPTX
Verilog operators.pptx
VandanaPagar1
 
PDF
VERILOG CODE FOR Adder
Rakesh kumar jha
 
PPT
8255 presentaion.ppt
kamlesh deshmukh
 
PPT
Programming with 8085-Microprocessor and interfacing
Amitabh Shukla
 
PDF
Verilog HDL CODES
OmkarDarekar6
 
PPT
Interfacing of io device to 8085
Nitin Ahire
 
PPTX
Verilog Tutorial - Verilog HDL Tutorial with Examples
E2MATRIX
 
DOC
Microprocessor Basics 8085-8255 ch-5
Neelam Kapoor
 
PDF
Verilog coding of demux 8 x1
Rakesh kumar jha
 
PPT
Verilog hdl
Muhammad Uzair Rasheed
 
PPTX
Verilog Test Bench
Dr.YNM
 
PPT
verilog
Shrikant Vaishnav
 
PPTX
30. 8086 microprocessor pipelined architecture
sandip das
 
DOCX
Vlsi physical design-notes
Dr.YNM
 
PPTX
5.programmable interval timer 8253
MdFazleRabbi18
 
PDF
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
Ravikiran A
 
DOCX
ARM lab programs
revanasidha janbgi
 
PDF
Code GPU with CUDA - SIMT
Marina Kolpakova
 
Verilog Tasks & Functions
anand hd
 
8255 ppi
Suraj Bora
 
Verilog operators.pptx
VandanaPagar1
 
VERILOG CODE FOR Adder
Rakesh kumar jha
 
8255 presentaion.ppt
kamlesh deshmukh
 
Programming with 8085-Microprocessor and interfacing
Amitabh Shukla
 
Verilog HDL CODES
OmkarDarekar6
 
Interfacing of io device to 8085
Nitin Ahire
 
Verilog Tutorial - Verilog HDL Tutorial with Examples
E2MATRIX
 
Microprocessor Basics 8085-8255 ch-5
Neelam Kapoor
 
Verilog coding of demux 8 x1
Rakesh kumar jha
 
Verilog Test Bench
Dr.YNM
 
30. 8086 microprocessor pipelined architecture
sandip das
 
Vlsi physical design-notes
Dr.YNM
 
5.programmable interval timer 8253
MdFazleRabbi18
 
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
Ravikiran A
 
ARM lab programs
revanasidha janbgi
 
Code GPU with CUDA - SIMT
Marina Kolpakova
 

Viewers also liked (8)

PDF
8 bit single cycle processor
Dhaval Kaneria
 
PDF
FPGA Verilog Processor Design
Archana Udaranga
 
PPTX
Controller Implementation in Verilog
Anees Akhtar
 
DOCX
VERILOG CODE
Dhaval Kaneria
 
PPT
Assic 5th Lecture
babak danyal
 
PPTX
Design and simulation of sayeh processor using verilog copy 1445752708332
akanksha sharma
 
PDF
Mips implementation
hoang974
 
DOCX
Design of Elevator Controller using Verilog HDL
Vishesh Thakur
 
8 bit single cycle processor
Dhaval Kaneria
 
FPGA Verilog Processor Design
Archana Udaranga
 
Controller Implementation in Verilog
Anees Akhtar
 
VERILOG CODE
Dhaval Kaneria
 
Assic 5th Lecture
babak danyal
 
Design and simulation of sayeh processor using verilog copy 1445752708332
akanksha sharma
 
Mips implementation
hoang974
 
Design of Elevator Controller using Verilog HDL
Vishesh Thakur
 
Ad

Similar to Project single cyclemips processor_verilog (20)

PPTX
PROCESSOR AND CONTROL UNIT - unit 3 Architecture
Gunasundari Selvaraj
 
PDF
An Example MIPS
Sandra Long
 
PPTX
PROCESSOR AND CONTROL UNIT
Amirthavalli Senthil
 
PPT
Lec20 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Da...
Hsien-Hsin Sean Lee, Ph.D.
 
PDF
VLSI Final Design Project
Vignesh Ganesan
 
PPTX
MIPS IMPLEMENTATION.pptx
JEEVANANTHAMG6
 
DOCX
Attachment_ VHDL datasheet
jethro kimande
 
PPTX
Computer Architecture and Organization- THE PROCESSOR DESIGN
C.Helen Sulochana
 
PDF
Implementation Of MIPS Single Cycle Processor
Pramod Devireddy
 
PPT
Basic MIPS implementation
kavitha2009
 
PPT
Basic MIPS implementation
kavitha2009
 
PDF
VLSI Design Final Project - 32 bit ALU
Sachin Kumar Asokan
 
PDF
Lec 12-15 mips instruction set processor
Mayank Roy
 
PPT
basic structure of computers
Himanshu Chawla
 
DOCX
Readregister 1Readregister 2WriteregisterWri.docx
sedgar5
 
PPT
Unit 1 basic structure of computers
chidabdu
 
PDF
3. Single Cycle Data Path in computer architecture
bsse20142018
 
PPTX
THE PROCESSOR
Jai Sudhan
 
PPTX
DG M 4 ppt.pptx
Jumana74
 
PPTX
Unit iii
Janani S
 
PROCESSOR AND CONTROL UNIT - unit 3 Architecture
Gunasundari Selvaraj
 
An Example MIPS
Sandra Long
 
PROCESSOR AND CONTROL UNIT
Amirthavalli Senthil
 
Lec20 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Da...
Hsien-Hsin Sean Lee, Ph.D.
 
VLSI Final Design Project
Vignesh Ganesan
 
MIPS IMPLEMENTATION.pptx
JEEVANANTHAMG6
 
Attachment_ VHDL datasheet
jethro kimande
 
Computer Architecture and Organization- THE PROCESSOR DESIGN
C.Helen Sulochana
 
Implementation Of MIPS Single Cycle Processor
Pramod Devireddy
 
Basic MIPS implementation
kavitha2009
 
Basic MIPS implementation
kavitha2009
 
VLSI Design Final Project - 32 bit ALU
Sachin Kumar Asokan
 
Lec 12-15 mips instruction set processor
Mayank Roy
 
basic structure of computers
Himanshu Chawla
 
Readregister 1Readregister 2WriteregisterWri.docx
sedgar5
 
Unit 1 basic structure of computers
chidabdu
 
3. Single Cycle Data Path in computer architecture
bsse20142018
 
THE PROCESSOR
Jai Sudhan
 
DG M 4 ppt.pptx
Jumana74
 
Unit iii
Janani S
 
Ad

Project single cyclemips processor_verilog

  • 1. Designing a Single Cycle MIPS microprocessor in Verilog Harsha Yelisala Spring 2009
  • 2. Technology Profile The following technologies are used in this project, MIPS Processor Architecture. Verilog HDL. VHDL HDL. ModelSim 6.2 SE Timing Analysis SPIM
  • 3. Aim The Objectives of this project are 1. To design a Single Cycle MIPS Microprocessor in Verilog and simulate the design in Modelsim. 2. To get hands-on experience in Verilog coding. 3. To get working expertise in using the Modelsim PE Student Edition 6.6a. 4. To understand the various stages of a processor design. 5. To analyze a processor from timing perspective.
  • 4. Abstract Designing a processor is one of the most challenging tasks in chip designing industry. Being part of processor making is the ultimate goal of many hardware engineers. Hence a thorough understanding of working of a processor is of high importance. This project deals with designing a single cycle microprocessor in Verilog. The design is then simulated in Modelsim.
  • 5. Work Flow 1. Studying the data path of a processor from Computer Organization and Design, The Hardware Software Interface 3rd Edition 2004. 2. Creating Verilog modules for each functional unit of the datapath. 3. Testing the created modules with customized test benches. 4. Combining the designed modules to a single top module. 5. Verifying and testing the final module in Modelsim.
  • 6. Datapath The datapath of a processor has the following functional units. 1. ProgramCounter 2. Register File 3. Arithmetic Logic Unit 4. Instruction Memory 5. Data Memory 6. Adders 7. Multiplexors 8. Shifters 9. SignExtender and 10. Control Unit
  • 8. Control Information ALU Control Lines Function 0000 AND 0001 OR 0010 ADD 0110 SUB 0111 SLT 1100 NOR
  • 9. Alu Control Implementation-1 of 2 Opcode AluOp Operation Funct Field Desired ALU Action ALU Control output LW 00 load word XXXXXX add 0010 SW 00 store word XXXXXX add 0010 BEQ 01 branch equal XXXXXX sub 0110 R-type 10 add 100000 add 0010 R-type 10 sub 100010 sub 0110 R-type 10 and 100100 and 0000 R-type 10 or 100101 or 0001 R-type 10 slt 101010 set lessthan 0111
  • 10. Alu Control Implementation-2 of 2 AluOp 1 AluOp 0 F5 F4 F3 F2 F1 F0 Operation 0 0 X X X X X X 0010 X 1 X X X X X X 0110 1 X X X 0 0 0 0 0010 1 X X X 0 0 1 0 0110 1 X X X 0 1 0 0 0000 1 X X X 0 1 0 1 0001 1 X X X 1 0 1 0 0111
  • 11. Control Block Implementation Control R-Format LW SW BEQ RegDst 1 0 X X ALUSrc 0 1 1 0 MemtoReg 0 1 X X RegWrite 1 1 0 0 MemRead 0 1 0 0 MemWrite 0 0 1 0 Branch 0 0 0 1 AluOp1 1 0 0 0 AluOp 0 0 0 0 1
  • 12. ProgramCounter module PC(clock,reset,pcin,pcout); input clock; input reset; input [31:0] pcin; output [31:0] pcout; reg clk; reg [31:0] pcout; initial begin clk=clock; end always #5 clk = ~clk; always @(posegde(clk)) pcout<=pcin; endmodule
  • 13. RegisterFile module REGISTERS(ReadRegister1,ReadRegister2, WriteRegister, WriteData_reg,RegWrite,ReadData1,ReadData2); input [4:0] ReadRegister1, ReadRegister2, WriteRegister; input [31:0] WriteData_reg; input RegWrite; output [31:0] ReadData1, ReadData2; reg [31:0] ReadData1, ReadData2; reg [31:0] REG[0:31]; integer i; initial begin for(i=0;i<32;i=i+1) REG[i]=0; end always @(ReadRegister1,ReadRegister2,RegWrite,WriteRegister,WriteData_reg) if(RegWrite==1’b1) REG[WriteRegister]=WriteData_reg; else begin ReadData1 <= REG[ReadRegister1]; ReadData2 <= REG[ReadRegister2]; end endmodule
  • 14. ArithmeticLogicUnit module ALU(Read_data_1, Read_data_2, ALUControl, ALUresult, isZero); input [31:0] Read_data_1, Read_data_2; input [3:0] ALUControl; output [31:0]ALUresult, isZero; reg [31:0] ALUresult, isZero; reg [3:0] addcode, subcode, andcode, orcode, sltcode; initial begin addcode[3:0] <= 4’b0010; subcode[3:0] <= 4’b0110; andcode[3:0] <= 4’b0000; orcode[3:0] <= 4’b0001; sltcode[3:0] <= 4’b0111; end always @(Read_data_1, Read_data_2, ALUControl) if (ALUControl == addcode) //add ALUresult = Read_data_1 + Read_data_2; else if(ALUControl == subcode) //sub ALUresult = Read_data_1 - Read_data_2; else if(ALUControl == andcode) //and ALUresult = Read_data_1 & Read_data_2; else if(ALUControl == orcode) //or ALUresult = Read_data_1 | Read_data_2; else if(ALUControl == sltcode) //slt if(Read_data_1 < Read_data_2) ALUresult = 32’b00000000000000000000000000000001; else ALUresult = 32’b00000000000000000000000000000000; always @(Read_data_1, Read_data_2, ALUControl,ALUresult) if(ALUresult == 32’b0) isZero = 32’b00000000000000000000000000000001; else isZero = 32’b00000000000000000000000000000000; endmodule
  • 15. InstructionMemory module INSTRUCTIONMEMORY(ReadAddress,Instruction); input [31:0] ReadAddress; output [31:0] Instruction; reg [31:0] Instruction; reg [31:0] IMEM[0:64]; integer i; initial begin for(i=0;i<64;i=i+1) IMEM[i]=1’b0; end always @(ReadAddress) Instruction=IMEM[ReadAddress]; endmodule
  • 16. DataMemory module DATAMEMORY(Address,MemWrite,MemRead,WriteData,ReadData); input [31:0] Address; input MemWrite; input MemRead; input [31:0] WriteData; output [31:0] ReadData; reg [31:0] ReadData; reg [31:0] RAM[0:63]; integer i,j; initial begin for(i=0;i<64;i=i+1) for(j=0;j<32;j=j+1) RAM[i][j]<=0; end always @(Address,MemWrite,MemRead,WriteData) if(MemWrite==1’b1) RAM[Address]=WriteData; else if(MemRead==1’b1) ReadData=RAM[Address]; endmodule
  • 17. ControlUnit module CONTROL(opcode,RegDst,Branch,MemRead,MemtoReg,ALUOp,MemWrite,ALUSrc,RegWrite); input [6:0] opcode; output RegDst, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite; output [1:0] ALUOp; reg RegDst, Branch, MemRead, MemtoReg, MemWrite, ALUSrc, RegWrite; reg [1:0] ALUOp; always @(opcode) begin if(opcode==6’b000000) //r controls 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 if(opcode==6’b100011) //lw controls 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 if(opcode==6’b101011) //sw controls 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 if(opcode==6’b101011) //beq controls 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 end endmodule
  • 18. Adders and Multiplexors module ADD(data1, data2, sum); input [31:0] data1; input [31:0] data2; output [31:0]sum; reg [31:0]sum; always @(data1, data2) sum = data1 + data2; endmodule module MUX(mux_in_1,mux_in_2,sel,mux_out); input [31:0] mux_in_1; input [31:0] mux_in_2; input sel; output [31:0] mux_out; reg [31:0] mux_out; always @(mux_in_1,mux_in_2,sel) if(sel==1’b0) mux_out=mux_in_1; else mux_out=mux_in_2; endmodule
  • 19. Shifter and Signextender module SHIFTLEFT(shift_in,shift_out); input [31:0] shift_in; output [31:0] shift_out; reg [31:0] shift_out; reg [29:0] temp; always @(shift_in) shift_out= shift_in<<2; endmodule module SIGNEXTEND(sign_in, sign_out); input [15:0] sign_in; output [31:0] sign_out; reg [31:0] sign_out; reg [31:0] tmp; integer i; initial begin sign_out <=32’b0; end always @(sign_in) if(sign_in[15] == 0) sign_out = {32’b000000000000000000,sign_in}; else sign_out = {32’b111111111111111111,sign_in}; endmodule
  • 20. SingleCycleMIPSProcessor module SINGLECYCLEMIPSPROCESSOR(globalclock,globalreset); input globalclock; input globalreset; wire [31:0] _pcout; wire [31:0] _Instruction; wire [31:0] _ReadData1; wire [31:0] _ReadData2; wire _RegDst,_Branch,_MemRead,_MemtoReg,_MemWrite,_ALUSrc,_RegWrite; wire [1:0] _ALUOp; wire [31:0] _sign_out; wire [31:0] _shift_out; wire [31:0] _sum_pcplus4; wire [31:0] _sum_branchadder; wire _sel_regfiledest; wire [31:0] _mux_out_alusrc; wire _sel_alusrc; wire [31:0] _mux_out_branchornot; wire _sel_branchornot; wire [31:0] #20 _mux_out_regfiledata; wire [4:0] _mux_out_regfiledest_5b; wire [3:0] _ALUControl; wire [31:0] _ReadData; wire [31:0] _ALUresult; wire _isZero; //After Portmapping PC mypc(.clock(globalclock),.reset(globalreset),.pcin(_mux_out_branchornot),.pcout(_pcout)); INSTRUCTIONMEMORY myinstructionmemory(.ReadAddress(_pcout),.Instruction(_Instruction)); REGISTERS myregisters(.ReadRegister1(_Instruction[25:21]),.ReadRegister2(_Instruction[20:16]),.WriteRegister(_mux_out_regfiledest_5b),.WriteData_reg(_mux_out CONTROL mycontrol(.opcode(_Instruction[31:26]),.RegDst(_RegDst),.Branch(_Branch),.MemRead(_MemRead),.MemtoReg(_MemtoReg),.ALUOp(_ALUOp),.MemWrite(_MemWrite), SIGNEXTEND mysignextend( .sign_in(_Instruction[15:0]), .sign_out(_sign_out) ); SHIFTLEFT myshiftleft( .shift_in(_sign_out), .shift_out(_shift_out) ); ADDPLUS4 myadd_pc_plus4(.data1(_pcout), .sum(_sum_pcplus4)); ADD myadd_branchadder(.data1(_sum_pcplus4), .data2(_shift_out), .sum(_sum_branchadder)); MUX5B mymux_regfiledest( .mux_in_1(_Instruction[20:16]), .mux_in_2(_Instruction[15:11]), .sel(_RegDst), .mux_out(_mux_out_regfiledest_5b) ); MUX mymux_alusrc( .mux_in_1(_ReadData2), .mux_in_2(_sign_out), .sel(_ALUSrc), .mux_out(_mux_out_alusrc) ); AND a(_sel_branchornot,Branch,isZero); MUX mymux_branchornot( .mux_in_1(_sum_pcplus4), .mux_in_2(_sum_branchadder), .sel(_sel_branchornot), .mux_out(_mux_out_branchornot) ); MUX mymux_regfiledata( .mux_in_1(_ReadData), .mux_in_2(_ALUresult), .sel(_MemtoReg), .mux_out(_mux_out_regfiledata) ); ALUCONTROL myalucontrol( .ALUop(_ALUOp), .Funct(_Instruction[5:0]), .ALUControl(_ALUControl) ); DATAMEMORY mydatamemory(.Address(_ALUresult),.MemWrite(_MemWrite),.MemRead(_MemRead),.WriteData(_ReadData2),.ReadData(_ReadData)); ALU myalu( .Read_data_1(_ReadData1), .Read_data_2(_mux_out_alusrc), .ALUControl(_ALUControl), .ALUresult(_ALUresult),.isZero(_isZero) ); endmodule
  • 21. Pros-Cons Pros Simple to design CPI is always 1. Cons It is inefficient. Every clockcycle must have the same length as the longest possible path(Load instruction) in the design making the other instructions which work in lesser cycle time are forced to work for extra time. Though the CPI is 1, the overall system performance of the design is not good.
  • 22. Conclusion In this academic project, A single cycle MIPS microprocessor is designed. Understood the design flow for the datapath design in a Processor design. Experience gained in Verilog coding and debugging. Experience gained in usage of ModelSim 6.2 SE. Understood the necessity of Pipelining and other advanced techniques for processor design.