KhalidObaidy

Codes

Codes of the project
Showing 77 changed files with 1928 additions and 0 deletions
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// ALU Control unit
5 +module ALUControl_Block( ALUControl, ALUOp, Function);
6 +output [1:0] ALUControl;
7 +reg [1:0] ALUControl;
8 +input [1:0] ALUOp;
9 +input [5:0] Function;
10 +wire [7:0] ALUControlIn;
11 +assign ALUControlIn = {ALUOp,Function};
12 +always @(ALUControlIn)
13 +casex (ALUControlIn)
14 + 8'b11xxxxxx: ALUControl=2'b01;
15 + 8'b00xxxxxx: ALUControl=2'b00;
16 + 8'b01xxxxxx: ALUControl=2'b10;
17 + 8'b10100000: ALUControl=2'b00;
18 + 8'b10100010: ALUControl=2'b10;
19 + 8'b10101010: ALUControl=2'b11;
20 + default: ALUControl=2'b00;
21 + endcase
22 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Verilog code for 32-bit adder
5 +module Add(S,A,B);
6 +output [31:0] S;
7 +input [31:0] A,B;
8 +wire [31:0] C;
9 + adder1bit adder1bit0(S[0],C[0],A[0],B[0],1'b0);
10 + adder1bit adder1bit1(S[1],C[1],A[1],B[1],C[0]);
11 + adder1bit adder1bit2(S[2],C[2],A[2],B[2],C[1]);
12 + adder1bit adder1bit3(S[3],C[3],A[3],B[3],C[2]);
13 + adder1bit adder1bit4(S[4],C[4],A[4],B[4],C[3]);
14 + adder1bit adder1bit5(S[5],C[5],A[5],B[5],C[4]);
15 + adder1bit adder1bit6(S[6],C[6],A[6],B[6],C[5]);
16 + adder1bit adder1bit7(S[7],C[7],A[7],B[7],C[6]);
17 + adder1bit adder1bit8(S[8],C[8],A[8],B[8],C[7]);
18 + adder1bit adder1bit9(S[9],C[9],A[9],B[9],C[8]);
19 + adder1bit adder1bit10(S[10],C[10],A[10],B[10],C[9]);
20 + adder1bit adder1bit11(S[11],C[11],A[11],B[11],C[10]);
21 + adder1bit adder1bit12(S[12],C[12],A[12],B[12],C[11]);
22 + adder1bit adder1bit13(S[13],C[13],A[13],B[13],C[12]);
23 + adder1bit adder1bit14(S[14],C[14],A[14],B[14],C[13]);
24 + adder1bit adder1bit15(S[15],C[15],A[15],B[15],C[14]);
25 + adder1bit adder1bit16(S[16],C[16],A[16],B[16],C[15]);
26 + adder1bit adder1bit17(S[17],C[17],A[17],B[17],C[16]);
27 + adder1bit adder1bit18(S[18],C[18],A[18],B[18],C[17]);
28 + adder1bit adder1bit19(S[19],C[19],A[19],B[19],C[18]);
29 + adder1bit adder1bit20(S[20],C[20],A[20],B[20],C[19]);
30 + adder1bit adder1bit21(S[21],C[21],A[21],B[21],C[20]);
31 + adder1bit adder1bit22(S[22],C[22],A[22],B[22],C[21]);
32 + adder1bit adder1bit23(S[23],C[23],A[23],B[23],C[22]);
33 + adder1bit adder1bit24(S[24],C[24],A[24],B[24],C[23]);
34 + adder1bit adder1bit25(S[25],C[25],A[25],B[25],C[24]);
35 + adder1bit adder1bit26(S[26],C[26],A[26],B[26],C[25]);
36 + adder1bit adder1bit27(S[27],C[27],A[27],B[27],C[26]);
37 + adder1bit adder1bit28(S[28],C[28],A[28],B[28],C[27]);
38 + adder1bit adder1bit29(S[29],C[29],A[29],B[29],C[28]);
39 + adder1bit adder1bit30(S[30],C[30],A[30],B[30],C[29]);
40 + adder1bit adder1bit31(S[31],C[31],A[31],B[31],C[30]);
41 +
42 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Control unit
5 +module Control(
6 +RegDst,
7 +ALUSrc,
8 +MemtoReg,
9 +RegWrite,
10 +MemRead,
11 +MemWrite,
12 +Branch,
13 +ALUOp,
14 +Jump,
15 +SignZero,
16 +Opcode
17 +);
18 +
19 +output RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,Jump,SignZero;
20 +output [1:0] ALUOp;
21 +input [5:0] Opcode;
22 +reg RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,Jump,SignZero;
23 +reg [1:0] ALUOp;
24 +always @(*)
25 +casex (Opcode)
26 + 6'b000000 : begin // R - type
27 + RegDst = 1'b1;
28 + ALUSrc = 1'b0;
29 + MemtoReg= 1'b0;
30 + RegWrite= 1'b1;
31 + MemRead = 1'b0;
32 + MemWrite= 1'b0;
33 + Branch = 1'b0;
34 + ALUOp = 2'b10;
35 + Jump = 1'b0;
36 + SignZero= 1'b0;
37 + end
38 + 6'b100011 : begin // lw - load word
39 + RegDst = 1'b0;
40 + ALUSrc = 1'b1;
41 + MemtoReg= 1'b1;
42 + RegWrite= 1'b1;
43 + MemRead = 1'b1;
44 + MemWrite= 1'b0;
45 + Branch = 1'b0;
46 + ALUOp = 2'b00;
47 + Jump = 1'b0;
48 + SignZero= 1'b0; // sign extend
49 + end
50 + 6'b101011 : begin // sw - store word
51 + RegDst = 1'bx;
52 + ALUSrc = 1'b1;
53 + MemtoReg= 1'bx;
54 + RegWrite= 1'b0;
55 + MemRead = 1'b0;
56 + MemWrite= 1'b1;
57 + Branch = 1'b0;
58 + ALUOp = 2'b00;
59 + Jump = 1'b0;
60 + SignZero= 1'b0;
61 + end
62 + 6'b000101 : begin // bne - branch if not equal
63 + RegDst = 1'b0;
64 + ALUSrc = 1'b0;
65 + MemtoReg= 1'b0;
66 + RegWrite= 1'b0;
67 + MemRead = 1'b0;
68 + MemWrite= 1'b0;
69 + Branch = 1'b1;
70 + ALUOp = 2'b01;
71 + Jump = 1'b0;
72 + SignZero= 1'b0; // sign extend
73 + end
74 + 6'b001110 : begin // XORI - XOR immidiate
75 + RegDst = 1'b0;
76 + ALUSrc = 1'b1;
77 + MemtoReg= 1'b0;
78 + RegWrite= 1'b1;
79 + MemRead = 1'b0;
80 + MemWrite= 1'b0;
81 + Branch = 1'b0;
82 + ALUOp = 2'b11;
83 + Jump = 1'b0;
84 + SignZero= 1'b1; // zero extend
85 + end
86 + 6'b000010 : begin // j - Jump
87 + RegDst = 1'b0;
88 + ALUSrc = 1'b0;
89 + MemtoReg= 1'b0;
90 + RegWrite= 1'b0;
91 + MemRead = 1'b0;
92 + MemWrite= 1'b0;
93 + Branch = 1'b0;
94 + ALUOp = 2'b00;
95 + Jump = 1'b1;
96 + SignZero= 1'b0;
97 + end
98 + default : begin
99 + RegDst = 1'b0;
100 + ALUSrc = 1'b0;
101 + MemtoReg= 1'b0;
102 + RegWrite= 1'b0;
103 + MemRead = 1'b0;
104 + MemWrite= 1'b0;
105 + Branch = 1'b0;
106 + ALUOp = 2'b10;
107 + Jump = 1'b0;
108 + SignZero= 1'b0;
109 + end
110 +
111 +endcase
112 +
113 +endmodule
...\ No newline at end of file ...\ No newline at end of file
1 +module D_FF (q, d, reset, clk);
2 +output q;
3 +input d, reset, clk;
4 +reg q; // Indicate that q is stateholding
5 +
6 +always @(posedge clk or posedge reset)
7 +if (reset)
8 +q = 0; // On reset, set to 0
9 +else
10 +q = d; // Otherwise out = d
11 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// fpga4student.com: FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Forwarding Unit
5 +module ForwardingUnit(ForwardA,ForwardB,MEM_RegWrite,WB_RegWrite,MEM_WriteRegister,WB_WriteRegister,EX_rs,EX_rt);
6 +output [1:0] ForwardA,ForwardB;
7 +wire [1:0] ForwardA,ForwardB;
8 +input MEM_RegWrite,WB_RegWrite;
9 +input [4:0] MEM_WriteRegister,WB_WriteRegister,EX_rs,EX_rt;
10 +
11 +// a= 1 if ( MEM_WriteRegister != 0 )
12 +or #(50) orMEM_WriteReg(a,MEM_WriteRegister[4],MEM_WriteRegister[3],MEM_WriteRegister[2],MEM_WriteRegister[1],MEM_WriteRegister[0]);
13 +CompareAddress CompMEM_WriteReg_EXrs(b,MEM_WriteRegister,EX_rs);
14 +and #(50) andx(x,MEM_RegWrite,a,b);
15 +// x=1 if ((MEM_RegWrite==1)&&(MEM_WriteRegister != 0)&&(MEM_WriteRegister==EX_rs))
16 +
17 +// c= 1 if ( WB_WriteRegister != 0 )
18 +or #(50) orWB_WriteReg(c,WB_WriteRegister[4],WB_WriteRegister[3],WB_WriteRegister[2],WB_WriteRegister[1],WB_WriteRegister[0]);
19 +CompareAddress CompWB_WriteReg_EXrs(d,WB_WriteRegister,EX_rs);
20 +and #(50) andy(y,WB_RegWrite,c,d);
21 +// y=1 if ((WB_RegWrite==1)&&(WB_WriteRegister != 0)&&(WB_WriteRegister==EX_rs))
22 +
23 +// ForwardA[1] = x; va ForwardA[0] = (NOT x). y ;
24 +assign ForwardA[1] = x;
25 +not #(50) notxgate(notx,x);
26 +and #(50) NOTxANDy(ForwardA[0],notx,y);
27 +
28 +// ForwardB
29 +CompareAddress CompMEM_WriteReg_EXrt(b1,MEM_WriteRegister,EX_rt);
30 +CompareAddress CompWB_WriteReg_EXrt(d1,WB_WriteRegister,EX_rt);
31 +and #(50) andx1(x1,MEM_RegWrite,a,b1);
32 +and #(50) andy1(y1,WB_RegWrite,c,d1);
33 +
34 +assign ForwardB[1] = x1;
35 +not #(50) notx1gate(notx1,x1);
36 +and #(50) NOTx1ANDy1(ForwardB[0],notx1,y1);
37 +endmodule
1 +/* Instruction memory module. */
2 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
3 +// Instruction memory module
4 +`timescale 1 ps / 100 fs
5 +module InstructionMem(instruction, address);
6 +
7 +input [31:0] address;
8 +output [31:0] instruction;
9 +reg [31:0]instrmem[1023:0];
10 +reg [31:0] temp;
11 +
12 +buf #1000 buf0(instruction[0],temp[0]),
13 + buf1(instruction[1],temp[1]),
14 + buf2(instruction[2],temp[2]),
15 + buf3(instruction[3],temp[3]),
16 + buf4(instruction[4],temp[4]),
17 + buf5(instruction[5],temp[5]),
18 + buf6(instruction[6],temp[6]),
19 + buf7(instruction[7],temp[7]),
20 + buf8(instruction[8],temp[8]),
21 + buf9(instruction[9],temp[9]),
22 + buf10(instruction[10],temp[10]),
23 + buf11(instruction[11],temp[11]),
24 + buf12(instruction[12],temp[12]),
25 + buf13(instruction[13],temp[13]),
26 + buf14(instruction[14],temp[14]),
27 + buf15(instruction[15],temp[15]),
28 + buf16(instruction[16],temp[16]),
29 + buf17(instruction[17],temp[17]),
30 + buf18(instruction[18],temp[18]),
31 + buf19(instruction[19],temp[19]),
32 + buf20(instruction[20],temp[20]),
33 + buf21(instruction[21],temp[21]),
34 + buf22(instruction[22],temp[22]),
35 + buf23(instruction[23],temp[23]),
36 + buf24(instruction[24],temp[24]),
37 + buf25(instruction[25],temp[25]),
38 + buf26(instruction[26],temp[26]),
39 + buf27(instruction[27],temp[27]),
40 + buf28(instruction[28],temp[28]),
41 + buf29(instruction[29],temp[29]),
42 + buf30(instruction[30],temp[30]),
43 + buf31(instruction[31],temp[31]);
44 +
45 +always @(address)
46 +begin
47 + temp=instrmem[address/4];
48 +end
49 +
50 +initial
51 +begin
52 +$readmemb("instr.txt", instrmem);
53 +end
54 +
55 +endmodule
56 +
57 +
58 +module instrmemstimulous();
59 +
60 +reg [31:0] addr;
61 +wire [31:0] instr;
62 +
63 +InstructionMem instructionmemory(instr, addr);
64 +
65 +initial
66 +begin
67 +$monitor("Mem Address=%h instruction=%b",addr,instr);
68 +addr=32'd0;
69 +#10000 addr=32'd4;
70 +#10000 addr=32'd8;
71 +#10000 addr=32'd12;
72 +#10000 addr=32'd16;
73 +#10000 addr=32'd20;
74 +#10000 addr=32'd24;
75 +#10000 addr=32'd28;
76 +#10000;
77 +$finish;
78 +end
79 +
80 +endmodule
1 +/* Instruction memory module. */
2 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
3 +// Instruction memory module
4 +`timescale 1 ps / 100 fs
5 +module InstructionMem(instruction, address);
6 +
7 +input [31:0] address;
8 +output [31:0] instruction;
9 +reg [31:0]instrmem[1023:0];
10 +reg [31:0] temp;
11 +
12 +buf #1000 buf0(instruction[0],temp[0]),
13 + buf1(instruction[1],temp[1]),
14 + buf2(instruction[2],temp[2]),
15 + buf3(instruction[3],temp[3]),
16 + buf4(instruction[4],temp[4]),
17 + buf5(instruction[5],temp[5]),
18 + buf6(instruction[6],temp[6]),
19 + buf7(instruction[7],temp[7]),
20 + buf8(instruction[8],temp[8]),
21 + buf9(instruction[9],temp[9]),
22 + buf10(instruction[10],temp[10]),
23 + buf11(instruction[11],temp[11]),
24 + buf12(instruction[12],temp[12]),
25 + buf13(instruction[13],temp[13]),
26 + buf14(instruction[14],temp[14]),
27 + buf15(instruction[15],temp[15]),
28 + buf16(instruction[16],temp[16]),
29 + buf17(instruction[17],temp[17]),
30 + buf18(instruction[18],temp[18]),
31 + buf19(instruction[19],temp[19]),
32 + buf20(instruction[20],temp[20]),
33 + buf21(instruction[21],temp[21]),
34 + buf22(instruction[22],temp[22]),
35 + buf23(instruction[23],temp[23]),
36 + buf24(instruction[24],temp[24]),
37 + buf25(instruction[25],temp[25]),
38 + buf26(instruction[26],temp[26]),
39 + buf27(instruction[27],temp[27]),
40 + buf28(instruction[28],temp[28]),
41 + buf29(instruction[29],temp[29]),
42 + buf30(instruction[30],temp[30]),
43 + buf31(instruction[31],temp[31]);
44 +
45 +always @(address)
46 +begin
47 + temp=instrmem[address/4];
48 +end
49 +
50 +initial
51 +begin
52 +$readmemb("instr.txt", instrmem);
53 +end
54 +
55 +endmodule
56 +
57 +
58 +module instrmemstimulous();
59 +
60 +reg [31:0] addr;
61 +wire [31:0] instr;
62 +
63 +InstructionMem instructionmemory(instr, addr);
64 +
65 +initial
66 +begin
67 +$monitor("Mem Address=%h instruction=%b",addr,instr);
68 +addr=32'd0;
69 +#10000 addr=32'd4;
70 +#10000 addr=32'd8;
71 +#10000 addr=32'd12;
72 +#10000 addr=32'd16;
73 +#10000 addr=32'd20;
74 +#10000 addr=32'd24;
75 +#10000 addr=32'd28;
76 +#10000;
77 +$finish;
78 +end
...\ No newline at end of file ...\ No newline at end of file
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Control singals for JR instruction
5 +module JRControl_Block( JRControl, ALUOp, Function);
6 +output JRControl;
7 +reg JRControl;
8 +input [1:0] ALUOp;
9 +input [5:0] Function;
10 +wire [7:0] test;
11 +assign test = {ALUOp,Function};
12 +always @(test)
13 +case (test)
14 + 8'b10001000 : JRControl=1'b1;
15 + default: JRControl=1'b0;
16 + endcase
17 +endmodule
1 +`timescale 1 ps / 100 fs
2 +module MIPSStimulus();
3 +// FPGA projects, Verilog Projects, VHDL projects
4 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
5 +// Testbench Verilog code for 32-bit 5-stage Pipelined MIPS Processor
6 +parameter ClockDelay = 5000;
7 +
8 +reg clk,reset;
9 +
10 +
11 +MIPSpipeline myMIPS(clk, reset);
12 +initial clk = 0;
13 +always #(ClockDelay/2) clk = ~clk;
14 +
15 +initial
16 +begin
17 + reset = 1;
18 + #(ClockDelay/4);
19 + reset = 0;
20 +end
21 +endmodule
1 +`timescale 1 ps / 100 fs
2 +module MIPSStimulus();
3 +// FPGA projects, Verilog Projects, VHDL projects
4 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
5 +// Testbench Verilog code for 32-bit 5-stage Pipelined MIPS Processor
6 +parameter ClockDelay = 5000;
7 +
8 +reg clk,reset;
9 +
10 +
11 +MIPSpipeline myMIPS(clk, reset);
12 +initial clk = 0;
13 +always #(ClockDelay/2) clk = ~clk;
14 +
15 +initial
16 +begin
17 + reset = 1;
18 + #(ClockDelay/4);
19 + reset = 0;
20 +end
21 +endmodule
1 +`timescale 1 ps / 100 fs
2 +//Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Top level Verilog code for 32-bit 5-stage Pipelined MIPS Processor
5 +module MIPSpipeline(clk, reset);
6 +input clk, reset;
7 +wire [31:0] PC, PCin;
8 +wire [31:0] PC4,ID_PC4,EX_PC4;
9 +wire [31:0] PCbne,PC4bne,PCj,PC4bnej,PCjr; // PC signals in MUX
10 +wire [31:0] Instruction,ID_Instruction,EX_Instruction; // Output of Instruction Memory
11 +wire [5:0] Opcode,Function; // Opcode, Function
12 +
13 +// Extend
14 +wire [15:0] imm16; // immediate in I type instruction
15 +wire [31:0] Im16_Ext,EX_Im16_Ext;
16 +wire [31:0] sign_ext_out,zero_ext_out;
17 +// regfile
18 +wire [4:0] rs,rt,rd,EX_rs,EX_rt,EX_rd,EX_WriteRegister,MEM_WriteRegister,WB_WriteRegister;
19 +wire [31:0] WB_WriteData, ReadData1, ReadData2,ReadData1Out,ReadData2Out, EX_ReadData1, EX_ReadData2;
20 +
21 +// ALU
22 +wire [31:0] Bus_A_ALU,Bus_B_ALU,Bus_B_forwarded;
23 +wire [31:0] EX_ALUResult,MEM_ALUResult,WB_ALUResult;
24 +wire ZeroFlag, OverflowFlag, CarryFlag, NegativeFlag,notZeroFlag;
25 +
26 +wire [31:0] WriteDataOfMem,MEM_ReadDataOfMem,WB_ReadDataOfMem;
27 +
28 +//Control signals
29 +wire RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,Jump,SignZero,JRControl;
30 +wire ID_RegDst,ID_ALUSrc,ID_MemtoReg,ID_RegWrite,ID_MemRead,ID_MemWrite,ID_Branch,ID_JRControl;
31 +wire EX_RegDst,EX_ALUSrc,EX_MemtoReg,EX_RegWrite,EX_MemRead,EX_MemWrite,EX_Branch,EX_JRControl;
32 +wire MEM_MemtoReg,MEM_RegWrite,MEM_MemRead,MEM_MemWrite;
33 +wire WB_MemtoReg,WB_RegWrite;
34 +wire [1:0] ALUOp,ID_ALUOp,EX_ALUOp;
35 +wire [1:0] ALUControl;
36 +wire bneControl,notbneControl;
37 +wire JumpControl,JumpFlush;
38 +wire [1:0] ForwardA,ForwardB;
39 + //flush
40 +wire IF_flush,IFID_flush,notIFID_flush,Stall_flush,flush;
41 +//shift left
42 +wire [31:0] shiftleft2_bne_out,shiftleft2_jump_out; // shift left output
43 +// PC Write Enable, IF/ID Write Enable
44 +wire PC_WriteEn,IFID_WriteEn;
45 +
46 +
47 +//====== PC register======
48 +register PC_Reg(PC,PCin,PC_WriteEn,reset,clk);
49 +Add Add1(PC4,PC,{29'b0,3'b100}); // PC4 = PC + 4
50 +
51 +InstructionMem InstructionMem1(Instruction, PC);
52 +
53 +// register IF/ID
54 +
55 +register IFID_PC4(ID_PC4,PC4,IFID_WriteEn,reset,clk);
56 +register IFID_Instruction(ID_Instruction,Instruction,IFID_WriteEn,reset,clk);
57 +RegBit IF_flush_bit(IFID_flush,IF_flush, IFID_WriteEn,reset, clk);
58 +
59 +//========= ID STAGE===========
60 +assign Opcode = ID_Instruction[31:26];
61 +assign Function = ID_Instruction[5:0];
62 +assign rs = ID_Instruction[25:21];
63 +assign rt = ID_Instruction[20:16];
64 +assign rd = ID_Instruction[15:11];
65 +assign imm16= ID_Instruction[15:0];
66 +
67 + // Main Control
68 +Control MainControl(
69 +RegDst,
70 +ALUSrc,
71 +MemtoReg,
72 +RegWrite,
73 +MemRead,
74 +MemWrite,
75 +Branch,
76 +ALUOp,
77 +Jump,
78 +SignZero,
79 +Opcode
80 +);
81 +
82 + // Regfile
83 +regfile Register_File(
84 +ReadData1,
85 +ReadData2,
86 +WB_WriteData,
87 +rs,
88 +rt,
89 +WB_WriteRegister,
90 +WB_RegWrite,
91 +reset,
92 +clk);
93 +
94 +// forward Read Data if Write and Read at the same time
95 +WB_forward WB_forward_block(ReadData1Out,ReadData2Out,ReadData1,ReadData2,rs,rt,WB_WriteRegister,WB_WriteData,WB_RegWrite);
96 + // Sign-extend
97 +sign_extend sign_extend1(sign_ext_out,imm16);
98 + // Zero-extend
99 +zero_extend zero_extend1(zero_ext_out,imm16);
100 + // immediate extend: sign or zero
101 +mux2x32to32 muxSignZero( Im16_Ext,sign_ext_out,zero_ext_out, SignZero);
102 +
103 +JRControl_Block JRControl_Block1( JRControl, ALUOp, Function);
104 +
105 +Discard_Instr Discard_Instr_Block(ID_flush,IF_flush,JumpControl,bneControl,EX_JRControl);
106 +
107 +or #(50) OR_flush(flush,ID_flush,IFID_flush,Stall_flush);
108 +flush_block flush_block1(ID_RegDst,ID_ALUSrc,ID_MemtoReg,ID_RegWrite,ID_MemRead,ID_MemWrite,ID_Branch,ID_ALUOp,
109 +ID_JRControl,flush,RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,ALUOp,JRControl);
110 +
111 +//==========EX STAGE=========================
112 +// thanh ghi ID/EX
113 +register IDEX_PC4(EX_PC4,ID_PC4,1'b1,reset,clk);
114 +
115 +register IDEX_ReadData1(EX_ReadData1,ReadData1Out,1'b1,reset,clk);
116 +register IDEX_ReadData2(EX_ReadData2,ReadData2Out,1'b1,reset,clk);
117 +
118 +
119 +register IDEX_Im16_Ext(EX_Im16_Ext,Im16_Ext,1'b1,reset,clk);
120 +register IDEX_rs_rt_rd(EX_Instruction[31:0],ID_Instruction,1'b1,reset,clk);
121 +assign EX_rs = EX_Instruction[25:21];
122 +assign EX_rt = EX_Instruction[20:16];
123 +assign EX_rd = EX_Instruction[15:11];
124 +// 9 control signals via ID/EX
125 +RegBit IDEX_RegDst(EX_RegDst, ID_RegDst, 1'b1,reset, clk);
126 +RegBit IDEX_ALUSrc(EX_ALUSrc, ID_ALUSrc, 1'b1,reset, clk);
127 +RegBit IDEX_MemtoReg(EX_MemtoReg, ID_MemtoReg, 1'b1,reset, clk);
128 +RegBit IDEX_RegWrite(EX_RegWrite, ID_RegWrite, 1'b1,reset, clk);
129 +RegBit IDEX_MemRead(EX_MemRead, ID_MemRead, 1'b1,reset, clk);
130 +RegBit IDEX_MemWrite(EX_MemWrite, ID_MemWrite, 1'b1,reset, clk);
131 +RegBit IDEX_Branch(EX_Branch, ID_Branch, 1'b1,reset, clk);
132 +RegBit IDEX_JRControl(EX_JRControl, ID_JRControl, 1'b1,reset, clk);
133 +RegBit IDEX_ALUOp1(EX_ALUOp[1], ID_ALUOp[1], 1'b1,reset, clk);
134 +RegBit IDEX_ALUOp0(EX_ALUOp[0], ID_ALUOp[0], 1'b1,reset, clk);
135 +// Forwarding unit
136 +ForwardingUnit Forwarding_Block(ForwardA,ForwardB,MEM_RegWrite,WB_RegWrite,MEM_WriteRegister,WB_WriteRegister,EX_rs,EX_rt);
137 +// mux 3 x32 to 32 to choose source of ALU (forwarding)
138 +mux3x32to32 mux3A(Bus_A_ALU,EX_ReadData1,MEM_ALUResult,WB_WriteData,ForwardA);
139 +mux3x32to32 mux3B(Bus_B_forwarded,EX_ReadData2,MEM_ALUResult,WB_WriteData,ForwardB);
140 +// mux 2x32 to 32 to select source Bus B of ALU
141 +mux2x32to32 muxALUSrc( Bus_B_ALU,Bus_B_forwarded,EX_Im16_Ext, EX_ALUSrc);
142 +// ALU Control
143 +ALUControl_Block ALUControl_Block1( ALUControl, EX_ALUOp, EX_Im16_Ext[5:0]);
144 +// EX_Im16_Ext[5:0] is function
145 +
146 +// ALU
147 +alu alu_block(EX_ALUResult, CarryFlag, ZeroFlag, OverflowFlag, NegativeFlag, Bus_A_ALU, Bus_B_ALU, ALUControl);
148 +
149 +// mux 2x5 to 5 choose shift register is Rd or Rt
150 +mux2x5to5 muxRegDst( EX_WriteRegister,EX_rt,EX_rd, EX_RegDst);
151 +
152 +//==============MEM STAGE=================
153 +// register EX/MEM
154 +register EXMEM_ALUResult(MEM_ALUResult,EX_ALUResult,1'b1,reset,clk);
155 +register EXMEM_WriteDataOfMem(WriteDataOfMem, Bus_B_forwarded,1'b1,reset,clk);
156 +RegBit EXMEM_MemtoReg(MEM_MemtoReg, EX_MemtoReg, 1'b1,reset, clk);
157 +RegBit EXMEM_RegWrite(MEM_RegWrite, EX_RegWrite, 1'b1,reset, clk);
158 +RegBit EXMEM_MemRead(MEM_MemRead, EX_MemRead, 1'b1,reset, clk);
159 +RegBit EXMEM_MemWrite(MEM_MemWrite, EX_MemWrite, 1'b1,reset, clk);
160 +RegBit EXMEM_WriteRegister4(MEM_WriteRegister[4], EX_WriteRegister[4], 1'b1,reset, clk);
161 +RegBit EXMEM_WriteRegister3(MEM_WriteRegister[3], EX_WriteRegister[3], 1'b1,reset, clk);
162 +RegBit EXMEM_WriteRegister2(MEM_WriteRegister[2], EX_WriteRegister[2], 1'b1,reset, clk);
163 +RegBit EXMEM_WriteRegister1(MEM_WriteRegister[1], EX_WriteRegister[1], 1'b1,reset, clk);
164 +RegBit EXMEM_WriteRegister0(MEM_WriteRegister[0], EX_WriteRegister[0], 1'b1,reset, clk);
165 +
166 + // Data Memory
167 +dataMem dataMem1(MEM_ReadDataOfMem, //data
168 + MEM_ALUResult, //address
169 + WriteDataOfMem, //writedata
170 + MEM_MemWrite, //writeenable
171 + MEM_MemRead,
172 + clk);
173 +//==========WB STAGE====================
174 +// register MEM/WB
175 +register MEMWB_ReadDataOfMem(WB_ReadDataOfMem,MEM_ReadDataOfMem,1'b1,reset,clk);
176 +register MEMWB_ALUResult(WB_ALUResult,MEM_ALUResult,1'b1,reset,clk);
177 +RegBit MEMWB_WriteRegister4(WB_WriteRegister[4], MEM_WriteRegister[4], 1'b1,reset, clk);
178 +RegBit MEMWB_WriteRegister3(WB_WriteRegister[3], MEM_WriteRegister[3], 1'b1,reset, clk);
179 +RegBit MEMWB_WriteRegister2(WB_WriteRegister[2], MEM_WriteRegister[2], 1'b1,reset, clk);
180 +RegBit MEMWB_WriteRegister1(WB_WriteRegister[1], MEM_WriteRegister[1], 1'b1,reset, clk);
181 +RegBit MEMWB_WriteRegister0(WB_WriteRegister[0], MEM_WriteRegister[0], 1'b1,reset, clk);
182 +
183 +RegBit MEMWB_MemtoReg(WB_MemtoReg, MEM_MemtoReg, 1'b1,reset, clk);
184 +RegBit MEMWB_RegWrite(WB_RegWrite, MEM_RegWrite, 1'b1,reset, clk);
185 +
186 + // Select Data to WriteData for regfile
187 +mux2x32to32 muxMemtoReg( WB_WriteData, WB_ALUResult, WB_ReadDataOfMem,WB_MemtoReg);
188 +
189 +//Stalling
190 +StallControl StallControl_block(PC_WriteEn,IFID_WriteEn,Stall_flush,EX_MemRead,EX_rt,rs,rt,Opcode);
191 +
192 +//Jump,bne, JRs
193 + // bne: Branch if not equal
194 +shift_left_2 shiftleft2_bne(shiftleft2_bne_out, EX_Im16_Ext);
195 +Add Add_bne(PCbne,EX_PC4,shiftleft2_bne_out);
196 +not #(50) notZero(notZeroFlag,ZeroFlag);
197 +and #(50) andbneControl(bneControl,EX_Branch,notZeroFlag);
198 +mux2x32to32 muxbneControl( PC4bne,PC4, PCbne, bneControl);
199 + // jump
200 +shift_left_2 shiftleft2_jump(shiftleft2_jump_out, {6'b0,ID_Instruction[25:0]});
201 +assign PCj = {ID_PC4[31:28],shiftleft2_jump_out[27:0]};
202 +
203 +not #(50) notIFIDFlush(notIFID_flush,IFID_flush);
204 +and #(50) andJumpFlush(JumpFlush,Jump,notIFID_flush);
205 +not #(50) notbne(notbneControl,bneControl);
206 +and #(50) andJumpBNE(JumpControl,JumpFlush,notbneControl);
207 +mux2x32to32 muxJump( PC4bnej,PC4bne, PCj, JumpControl);
208 +
209 + // JR: Jump Register
210 +assign PCjr = Bus_A_ALU;
211 +mux2x32to32 muxJR( PCin,PC4bnej, PCjr, EX_JRControl);
212 +
213 +endmodule
1 +module RegBit(BitOut, BitData, WriteEn,reset, clk);
2 +output BitOut; // 1 bit of register
3 +input BitData, WriteEn;
4 +input reset,clk;
5 +wire d,f1, f2; // input of D Flip-Flop
6 +wire reset;
7 +//assign reset=0;
8 +and #(50) U1(f1, BitOut, (~WriteEn));
9 +and #(50) U2(f2, BitData, WriteEn);
10 +or #(50) U3(d, f1, f2);
11 +D_FF DFF0(BitOut, d, reset, clk);
12 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Stall Control
5 +module StallControl(PC_WriteEn,IFID_WriteEn,Stall_flush,EX_MemRead,EX_rt,ID_rs,ID_rt,ID_Op);
6 +output PC_WriteEn,IFID_WriteEn,Stall_flush;
7 +wire PC_WriteEn,IFID_WriteEn,Stall_flush;
8 +input EX_MemRead,EX_rt,ID_rs,ID_rt;
9 +input [5:0] ID_Op;
10 +wire [4:0] EX_rt,ID_rs,ID_rt,xorRsRt,xorRtRt;
11 +wire [5:0] xoropcodelw,xoropcodexori;
12 +wire EX_MemRead;
13 +//wire xoropcode1,xoroprt;
14 +// write in behavior model
15 +/*always @(EX_MemRead or EX_rt or ID_rs or ID_rt)
16 +begin
17 + if ((EX_MemRead==1)&&((EX_rt==ID_rs)||((EX_rt==ID_rt)&&(Opcode!= 6'b001110)&&(Opcode!= 6'b100011)))
18 + begin
19 + PC_WriteEn=1'b0;
20 + IFID_WriteEn=1'b0;
21 + Stall_flush =1'b1;
22 + end
23 + else
24 + begin
25 + PC_WriteEn=1'b1;
26 + IFID_WriteEn=1'b1;
27 + Stall_flush =1'b0;
28 + end
29 +end
30 +*/
31 +// write in structural model
32 +xor #(50) xorRsRt4(xorRsRt[4],EX_rt[4],ID_rs[4]);
33 +xor #(50) xorRsRt3(xorRsRt[3],EX_rt[3],ID_rs[3]);
34 +xor #(50) xorRsRt2(xorRsRt[2],EX_rt[2],ID_rs[2]);
35 +xor #(50) xorRsRt1(xorRsRt[1],EX_rt[1],ID_rs[1]);
36 +xor #(50) xorRsRt0(xorRsRt[0],EX_rt[0],ID_rs[0]);
37 +or #(50) OrRsRt1(OrRsRt,xorRsRt[4],xorRsRt[3],xorRsRt[2],xorRsRt[1],xorRsRt[0]);
38 +not #(50) notgate1(notOrRsRt,OrRsRt);
39 +// neu EX_rt==ID_rs thi notOrRsRt = 1
40 +
41 +xor #(50) xorRtRt4(xorRtRt[4],EX_rt[4],ID_rt[4]);
42 +xor #(50) xorRtRt3(xorRtRt[3],EX_rt[3],ID_rt[3]);
43 +xor #(50) xorRtRt2(xorRtRt[2],EX_rt[2],ID_rt[2]);
44 +xor #(50) xorRtRt1(xorRtRt[1],EX_rt[1],ID_rt[1]);
45 +xor #(50) xorRtRt0(xorRtRt[0],EX_rt[0],ID_rt[0]);
46 +or #(50) OrRtRt1(OrRtRt,xorRtRt[4],xorRtRt[3],xorRtRt[2],xorRtRt[1],xorRtRt[0]);
47 +not #(50) notgate2(notOrRtRt,OrRtRt);
48 +// neu EX_rt==ID_rt thi notOrRtRt = 1
49 +xor #(50) xoropcode5(xoropcodelw[5],ID_Op[5],1'b1);
50 +xor #(50) xoropcode4(xoropcodelw[4],ID_Op[4],1'b0);
51 +xor #(50) xoropcode3(xoropcodelw[3],ID_Op[3],1'b0);
52 +xor #(50) xoropcode2(xoropcodelw[2],ID_Op[2],1'b0);
53 +xor #(50) xoropcode1(xoropcodelw[1],ID_Op[1],1'b1);
54 +xor #(50) xoropcode0(xoropcodelw[0],ID_Op[0],1'b1);
55 +or #(50) oropcode1(ec1,xoropcodelw[5],xoropcodelw[4],xoropcodelw[3],xoropcodelw[2],xoropcodelw[1],xoropcodelw[0]);
56 +// opcode != opcode[lw] xoropcodelw =1
57 +xor #(50) xoropcod5(xoropcodexori[5],ID_Op[5],1'b0);
58 +xor #(50) xoropcod4(xoropcodexori[4],ID_Op[4],1'b0);
59 +xor #(50) xoropcod3(xoropcodexori[3],ID_Op[3],1'b1);
60 +xor #(50) xoropcod2(xoropcodexori[2],ID_Op[2],1'b1);
61 +xor #(50) xoropcod1(xoropcodexori[1],ID_Op[1],1'b1);
62 +xor #(50) xoropcod0(xoropcodexori[0],ID_Op[0],1'b0);
63 +or #(50) oropcode2(ec2,xoropcodexori[5],xoropcodexori[4],xoropcodexori[3],xoropcodexori[2],xoropcodexori[1],xoropcodexori[0]);
64 +// opcode != opcode[xori] xoropcodexori =1
65 +
66 +and #(50) and1(xorop,ec1,ec2);
67 +and #(50) and2(xoroprt,xorop,notOrRtRt);
68 +or #(50) OrEXIDRsRt(OrOut,notOrRsRt,xoroprt);
69 +and #(50) AndCondition(Condition,EX_MemRead,OrOut);
70 +// Condition =1 when stall is satisfied
71 +not #(50) NotPC_WriteEn(PC_WriteEn,Condition);
72 +not #(50) NotIFID_WriteEn(IFID_WriteEn,Condition);
73 +buf #(50) bufStallflush(Stall_flush,Condition);
74 +endmodule
75 +
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Stall Control
5 +module StallControl(PC_WriteEn,IFID_WriteEn,Stall_flush,EX_MemRead,EX_rt,ID_rs,ID_rt,ID_Op);
6 +output PC_WriteEn,IFID_WriteEn,Stall_flush;
7 +wire PC_WriteEn,IFID_WriteEn,Stall_flush;
8 +input EX_MemRead,EX_rt,ID_rs,ID_rt;
9 +input [5:0] ID_Op;
10 +wire [4:0] EX_rt,ID_rs,ID_rt,xorRsRt,xorRtRt;
11 +wire [5:0] xoropcodelw,xoropcodexori;
12 +wire EX_MemRead;
13 +//wire xoropcode1,xoroprt;
14 +// write in behavior model
15 +always @(EX_MemRead or EX_rt or ID_rs or ID_rt)
16 +begin
17 + if ((EX_MemRead==1)&&((EX_rt==ID_rs)||((EX_rt==ID_rt)&&(Opcode!= 6'b001110)&&(Opcode!= 6'b100011)))
18 + begin
19 + PC_WriteEn=1'b0;
20 + IFID_WriteEn=1'b0;
21 + Stall_flush =1'b1;
22 + end
23 + else
24 + begin
25 + PC_WriteEn=1'b1;
26 + IFID_WriteEn=1'b1;
27 + Stall_flush =1'b0;
28 + end
29 +end
30 +
31 +// write in structural model
32 +xor #(50) xorRsRt4(xorRsRt[4],EX_rt[4],ID_rs[4]);
33 +xor #(50) xorRsRt3(xorRsRt[3],EX_rt[3],ID_rs[3]);
34 +xor #(50) xorRsRt2(xorRsRt[2],EX_rt[2],ID_rs[2]);
35 +xor #(50) xorRsRt1(xorRsRt[1],EX_rt[1],ID_rs[1]);
36 +xor #(50) xorRsRt0(xorRsRt[0],EX_rt[0],ID_rs[0]);
37 +or #(50) OrRsRt1(OrRsRt,xorRsRt[4],xorRsRt[3],xorRsRt[2],xorRsRt[1],xorRsRt[0]);
38 +not #(50) notgate1(notOrRsRt,OrRsRt);
39 +// neu EX_rt==ID_rs thi notOrRsRt = 1
40 +
41 +xor #(50) xorRtRt4(xorRtRt[4],EX_rt[4],ID_rt[4]);
42 +xor #(50) xorRtRt3(xorRtRt[3],EX_rt[3],ID_rt[3]);
43 +xor #(50) xorRtRt2(xorRtRt[2],EX_rt[2],ID_rt[2]);
44 +xor #(50) xorRtRt1(xorRtRt[1],EX_rt[1],ID_rt[1]);
45 +xor #(50) xorRtRt0(xorRtRt[0],EX_rt[0],ID_rt[0]);
46 +or #(50) OrRtRt1(OrRtRt,xorRtRt[4],xorRtRt[3],xorRtRt[2],xorRtRt[1],xorRtRt[0]);
47 +not #(50) notgate2(notOrRtRt,OrRtRt);
48 +// neu EX_rt==ID_rt thi notOrRtRt = 1
49 +xor #(50) xoropcode5(xoropcodelw[5],ID_Op[5],1'b1);
50 +xor #(50) xoropcode4(xoropcodelw[4],ID_Op[4],1'b0);
51 +xor #(50) xoropcode3(xoropcodelw[3],ID_Op[3],1'b0);
52 +xor #(50) xoropcode2(xoropcodelw[2],ID_Op[2],1'b0);
53 +xor #(50) xoropcode1(xoropcodelw[1],ID_Op[1],1'b1);
54 +xor #(50) xoropcode0(xoropcodelw[0],ID_Op[0],1'b1);
55 +or #(50) oropcode1(ec1,xoropcodelw[5],xoropcodelw[4],xoropcodelw[3],xoropcodelw[2],xoropcodelw[1],xoropcodelw[0]);
56 +// opcode != opcode[lw] xoropcodelw =1
57 +xor #(50) xoropcod5(xoropcodexori[5],ID_Op[5],1'b0);
58 +xor #(50) xoropcod4(xoropcodexori[4],ID_Op[4],1'b0);
59 +xor #(50) xoropcod3(xoropcodexori[3],ID_Op[3],1'b1);
60 +xor #(50) xoropcod2(xoropcodexori[2],ID_Op[2],1'b1);
61 +xor #(50) xoropcod1(xoropcodexori[1],ID_Op[1],1'b1);
62 +xor #(50) xoropcod0(xoropcodexori[0],ID_Op[0],1'b0);
63 +or #(50) oropcode2(ec2,xoropcodexori[5],xoropcodexori[4],xoropcodexori[3],xoropcodexori[2],xoropcodexori[1],xoropcodexori[0]);
64 +// opcode != opcode[xori] xoropcodexori =1
65 +
66 +and #(50) and1(xorop,ec1,ec2);
67 +and #(50) and2(xoroprt,xorop,notOrRtRt);
68 +or #(50) OrEXIDRsRt(OrOut,notOrRsRt,xoroprt);
69 +and #(50) AndCondition(Condition,EX_MemRead,OrOut);
70 +// Condition =1 when stall is satisfied
71 +not #(50) NotPC_WriteEn(PC_WriteEn,Condition);
72 +not #(50) NotIFID_WriteEn(IFID_WriteEn,Condition);
73 +buf #(50) bufStallflush(Stall_flush,Condition);
74 +endmodule
75 +
1 +`timescale 1 ps / 100 fs
2 +//: FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Write Back Forwarding
5 +module WB_forward(ReadData1Out,ReadData2Out,ReadData1,ReadData2,rs,rt,WriteRegister,WriteData,RegWrite);
6 +// WB Hazard: Reading data while writing
7 +// Solve Hazard at the WriteBack Stage
8 +output [31:0] ReadData1Out,ReadData2Out;
9 +input [31:0] ReadData1,ReadData2,WriteData;
10 +input [4:0] rs,rt,WriteRegister;
11 +input RegWrite;
12 +wire ReadSourceRs,ReadSourceRt;
13 +wire compOut1,compOut2;
14 +// behavior model
15 +/*
16 +always @(rs or rt or WriteRegister or WriteData or RegWrite)
17 +begin
18 + if ((RegWrite==1)&&(WriteRegister != 0)&&(WriteRegister==rs))
19 + ReadSourceRs = 1'b1; //Forwarding WriteData to ReadData1
20 + else
21 + ReadSourceRs = 1'b0;
22 + if ((RegWrite==1)&&(WriteRegister != 0)&&(WriteRegister==rt))
23 + ReadSourceRt = 1'b1; //Forwarding WriteData to ReadData2
24 + else
25 + ReadSourceRt = 1'b0;
26 +end
27 +*/
28 +// Structural model
29 +or #(50) orWriteReg(orOut1,WriteRegister[4],WriteRegister[3],WriteRegister[2],WriteRegister[1],WriteRegister[0]);
30 +CompareAddress Compare1(compOut1,WriteRegister,rs);
31 +and #(50) andCondition1(ReadSourceRs,RegWrite,orOut1,compOut1);
32 +
33 +CompareAddress Compare2(compOut2,WriteRegister,rt);
34 +and #(50) andCondition2(ReadSourceRt,RegWrite,orOut1,compOut2);
35 +
36 +mux2x32to32 muxReadData1( ReadData1Out,ReadData1,WriteData, ReadSourceRs);
37 +mux2x32to32 muxReadData2( ReadData2Out,ReadData2,WriteData, ReadSourceRt);
38 +endmodule
39 +`timescale 1 ps / 100 fs
40 +module CompareAddress(equal,Addr1,Addr2);
41 +// fpga4student.com: FPGA projects, Verilog Projects, VHDL projects
42 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
43 +// Compare Address
44 +output equal;
45 +wire equal;
46 +input [4:0] Addr1,Addr2;
47 +wire [4:0] Addr1,Addr2,xorAddress;
48 +xor #(50) xorAddress4(xorAddress[4],Addr1[4],Addr2[4]);
49 +xor #(50) xorAddress3(xorAddress[3],Addr1[3],Addr2[3]);
50 +xor #(50) xorAddress2(xorAddress[2],Addr1[2],Addr2[2]);
51 +xor #(50) xorAddress1(xorAddress[1],Addr1[1],Addr2[1]);
52 +xor #(50) xorAddress0(xorAddress[0],Addr1[0],Addr2[0]);
53 +or #(50) Orgate1(OrAddr,xorAddress[4],xorAddress[3],xorAddress[2],xorAddress[1],xorAddress[0]);
54 +not #(50) notgate1(equal,OrAddr);
55 +endmodule
1 +`timescale 1 ps / 100 fs
2 +module adder1bit(sum,cout,a,b,cin);
3 +input a,b,cin;
4 +output cout,sum;
5 +// sum = a xor b xor cin
6 +xor #(50) (sum,a,b,cin);
7 +// carry out = a.b + cin.(a+b)
8 +and #(50) and1(c1,a,b);
9 +or #(50) or1(c2,a,b);
10 +and #(50) and2(c3,c2,cin);
11 +or #(50) or2(cout,c1,c3);
12 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Verilog code for ALU
5 +module alu(Output, CarryOut, zero, overflow, negative, BussA, BussB, ALUControl);
6 +output CarryOut,overflow,negative,zero;
7 +output [31:0] Output;
8 +input [31:0] BussA,BussB;
9 +input [1:0] ALUControl;
10 +wire lessthan;
11 +wire [31:0] crrout;
12 +
13 +alu1bit alu0(Output[0],crrout[0],BussA[0],BussB[0],ALUControl[1],lessthan,ALUControl);
14 +alu1bit alu1(Output[1],crrout[1],BussA[1],BussB[1],crrout[0],1'b0,ALUControl);
15 +alu1bit alu2(Output[2],crrout[2],BussA[2],BussB[2],crrout[1],1'b0,ALUControl);
16 +alu1bit alu3(Output[3],crrout[3],BussA[3],BussB[3],crrout[2],1'b0,ALUControl);
17 +alu1bit alu4(Output[4],crrout[4],BussA[4],BussB[4],crrout[3],1'b0,ALUControl);
18 +alu1bit alu5(Output[5],crrout[5],BussA[5],BussB[5],crrout[4],1'b0,ALUControl);
19 +alu1bit alu6(Output[6],crrout[6],BussA[6],BussB[6],crrout[5],1'b0,ALUControl);
20 +alu1bit alu7(Output[7],crrout[7],BussA[7],BussB[7],crrout[6],1'b0,ALUControl);
21 +alu1bit alu8(Output[8],crrout[8],BussA[8],BussB[8],crrout[7],1'b0,ALUControl);
22 +alu1bit alu9(Output[9],crrout[9],BussA[9],BussB[9],crrout[8],1'b0,ALUControl);
23 +alu1bit alu10(Output[10],crrout[10],BussA[10],BussB[10],crrout[9],1'b0,ALUControl);
24 +alu1bit alu11(Output[11],crrout[11],BussA[11],BussB[11],crrout[10],1'b0,ALUControl);
25 +alu1bit alu12(Output[12],crrout[12],BussA[12],BussB[12],crrout[11],1'b0,ALUControl);
26 +alu1bit alu13(Output[13],crrout[13],BussA[13],BussB[13],crrout[12],1'b0,ALUControl);
27 +alu1bit alu14(Output[14],crrout[14],BussA[14],BussB[14],crrout[13],1'b0,ALUControl);
28 +alu1bit alu15(Output[15],crrout[15],BussA[15],BussB[15],crrout[14],1'b0,ALUControl);
29 +alu1bit alu16(Output[16],crrout[16],BussA[16],BussB[16],crrout[15],1'b0,ALUControl);
30 +alu1bit alu17(Output[17],crrout[17],BussA[17],BussB[17],crrout[16],1'b0,ALUControl);
31 +alu1bit alu18(Output[18],crrout[18],BussA[18],BussB[18],crrout[17],1'b0,ALUControl);
32 +alu1bit alu19(Output[19],crrout[19],BussA[19],BussB[19],crrout[18],1'b0,ALUControl);
33 +alu1bit alu20(Output[20],crrout[20],BussA[20],BussB[20],crrout[19],1'b0,ALUControl);
34 +alu1bit alu21(Output[21],crrout[21],BussA[21],BussB[21],crrout[20],1'b0,ALUControl);
35 +alu1bit alu22(Output[22],crrout[22],BussA[22],BussB[22],crrout[21],1'b0,ALUControl);
36 +alu1bit alu23(Output[23],crrout[23],BussA[23],BussB[23],crrout[22],1'b0,ALUControl);
37 +alu1bit alu24(Output[24],crrout[24],BussA[24],BussB[24],crrout[23],1'b0,ALUControl);
38 +alu1bit alu25(Output[25],crrout[25],BussA[25],BussB[25],crrout[24],1'b0,ALUControl);
39 +alu1bit alu26(Output[26],crrout[26],BussA[26],BussB[26],crrout[25],1'b0,ALUControl);
40 +alu1bit alu27(Output[27],crrout[27],BussA[27],BussB[26],crrout[26],1'b0,ALUControl);
41 +alu1bit alu28(Output[28],crrout[28],BussA[28],BussB[28],crrout[27],1'b0,ALUControl);
42 +alu1bit alu29(Output[29],crrout[29],BussA[29],BussB[29],crrout[28],1'b0,ALUControl);
43 +alu1bit alu30(Output[30],crrout[30],BussA[30],BussB[30],crrout[29],1'b0,ALUControl);
44 +alu1bit alu31(Output[31],crrout[31],BussA[31],BussB[31],crrout[30],1'b0,ALUControl);
45 +not #(50) notcarry(notcr31,crrout[31]);
46 +// Carryout = Not carry out 31 if it is subtraction
47 +mux21 muxcarry31(CarryOut,crrout[31],notcr31,ALUControl[1]);
48 +xor #(50) xor5(overflow,crrout[30],crrout[31]);
49 +// SLT
50 +addsub add2(addsub31Out,crrout31,BussA[31],BussB[31],crrout[30],ALUControl[1]);
51 +xor #(50) xor6(lessthan,overflow,addsub31Out);
52 +assign negative = Output[31];
53 +or #(50) or1(o1,Output[0],Output[1],Output[2],Output[3]);
54 +or #(50) or2(o2,Output[4],Output[5],Output[6],Output[7]);
55 +or #(50) or3(o3,Output[8],Output[9],Output[10],Output[11]);
56 +or #(50) or4(o4,Output[12],Output[13],Output[14],Output[15]);
57 +or #(50) or5(o5,Output[16],Output[17],Output[18],Output[19]);
58 +or #(50) or6(o6,Output[20],Output[21],Output[22],Output[23]);
59 +or #(50) or7(o7,Output[24],Output[25],Output[26],Output[27]);
60 +or #(50) or8(o8,Output[28],Output[29],Output[30],Output[31]);
61 +or #(50) or9(o9,o1,o2,o3,o4);
62 +or #(50) or10(o10,o5,o6,o7,o8);
63 +nor #(50) nor1(zero,o9,o10);
64 +endmodule
65 +`timescale 1 ps / 100 fs
66 +module alu1bit(result,crrout,a,b,carryin,less,ALUControl);
67 +output result,crrout;
68 +input a,b,carryin,less;
69 +input [1:0] ALUControl;
70 +addsub add1(addsubOut,crrout,a,b,carryin,ALUControl[1]);
71 +xor #(50) xor1(xorOut,a,b);
72 +mux21 mux2(xorlessOut,xorOut,less,ALUControl[1]);
73 +mux21 mux3(result,addsubOut,xorlessOut,ALUControl[0]);
74 +endmodule
75 +
76 +`timescale 1 ps / 100 fs
77 +module addsub(Out,cout,a,b,cin,select);
78 +input a,b,cin,select;
79 +output Out,cout; // the result and carry out
80 +not #(50) not1(notb,b);
81 +mux21 mux1(b1,b,notb,select);
82 +
83 +adder adder1(Out,cout,a,b1,cin);
84 +endmodule
85 +
86 +`timescale 1 ps / 100 fs
87 +module adder(sum,cout,a,b,cin);
88 +input a,b,cin;
89 +output cout,sum;
90 +// sum = a xor b xor cin
91 +xor #(50) (sum,a,b,cin);
92 +// carry out = a.b + cin.(a+b)
93 +and #(50) and1(c1,a,b);
94 +or #(50) or1(c2,a,b);
95 +and #(50) and2(c3,c2,cin);
96 +or #(50) or2(cout,c1,c3);
97 +endmodule
98 +
99 +`timescale 1 ps / 100 fs
100 +module mux21(O,A,B,sel);
101 +// sel = 0 thi O = A
102 +// sel = 1 thi O =B
103 +output O;
104 +input A,B,sel;
105 +not #(50) not1(nsel,sel);
106 +and #(50) and1(O1,A,nsel);
107 +and #(50) and2(O2,B,sel);
108 +or #(50) or2(O,O1,O2);
109 +endmodule
1 +module andmore(g,a,b,c,d,e);
2 + output g;
3 + input a,b,c,d,e;
4 + and #(50) and1(f1,a,b,c,d),
5 + and2(g,f1,e);
6 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Data Memory
5 +module dataMem(data, address, writedata, writeenable,MemRead,clk);
6 +
7 +input [31:0] address, writedata;
8 +input writeenable,MemRead, clk;
9 +output [31:0] data;
10 +reg [7:0] datamem[1023:0];
11 +reg [31:0] temp;
12 +
13 +buf #1000 buf0(data[0],temp[0]),
14 + buf1(data[1],temp[1]),
15 + buf2(data[2],temp[2]),
16 + buf3(data[3],temp[3]),
17 + buf4(data[4],temp[4]),
18 + buf5(data[5],temp[5]),
19 + buf6(data[6],temp[6]),
20 + buf7(data[7],temp[7]),
21 + buf8(data[8],temp[8]),
22 + buf9(data[9],temp[9]),
23 + buf10(data[10],temp[10]),
24 + buf11(data[11],temp[11]),
25 + buf12(data[12],temp[12]),
26 + buf13(data[13],temp[13]),
27 + buf14(data[14],temp[14]),
28 + buf15(data[15],temp[15]),
29 + buf16(data[16],temp[16]),
30 + buf17(data[17],temp[17]),
31 + buf18(data[18],temp[18]),
32 + buf19(data[19],temp[19]),
33 + buf20(data[20],temp[20]),
34 + buf21(data[21],temp[21]),
35 + buf22(data[22],temp[22]),
36 + buf23(data[23],temp[23]),
37 + buf24(data[24],temp[24]),
38 + buf25(data[25],temp[25]),
39 + buf26(data[26],temp[26]),
40 + buf27(data[27],temp[27]),
41 + buf28(data[28],temp[28]),
42 + buf29(data[29],temp[29]),
43 + buf30(data[30],temp[30]),
44 + buf31(data[31],temp[31]);
45 +
46 +always @(posedge clk)
47 + if (writeenable)
48 + begin
49 + datamem[address]=writedata[31:24];
50 + datamem[address+1]=writedata[23:16];
51 + datamem[address+2]=writedata[15:8];
52 + datamem[address+3]=writedata[7:0];
53 + end
54 +
55 +always @(address or datamem[address] or datamem[address+1] or datamem[address+2] or datamem[address+3])
56 +begin
57 + temp={datamem[address],datamem[address+1],datamem[address+2],datamem[address+3]};
58 +end
59 +
60 + initial
61 + begin
62 + $readmemh("data.dat", datamem);
63 + end
64 +
65 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Data Memory
5 +module dataMem(data, address, writedata, writeenable,MemRead,clk);
6 +
7 +input [31:0] address, writedata;
8 +input writeenable,MemRead, clk;
9 +output [31:0] data;
10 +reg [7:0] datamem[1023:0];
11 +reg [31:0] temp;
12 +
13 +buf #1000 buf0(data[0],temp[0]),
14 + buf1(data[1],temp[1]),
15 + buf2(data[2],temp[2]),
16 + buf3(data[3],temp[3]),
17 + buf4(data[4],temp[4]),
18 + buf5(data[5],temp[5]),
19 + buf6(data[6],temp[6]),
20 + buf7(data[7],temp[7]),
21 + buf8(data[8],temp[8]),
22 + buf9(data[9],temp[9]),
23 + buf10(data[10],temp[10]),
24 + buf11(data[11],temp[11]),
25 + buf12(data[12],temp[12]),
26 + buf13(data[13],temp[13]),
27 + buf14(data[14],temp[14]),
28 + buf15(data[15],temp[15]),
29 + buf16(data[16],temp[16]),
30 + buf17(data[17],temp[17]),
31 + buf18(data[18],temp[18]),
32 + buf19(data[19],temp[19]),
33 + buf20(data[20],temp[20]),
34 + buf21(data[21],temp[21]),
35 + buf22(data[22],temp[22]),
36 + buf23(data[23],temp[23]),
37 + buf24(data[24],temp[24]),
38 + buf25(data[25],temp[25]),
39 + buf26(data[26],temp[26]),
40 + buf27(data[27],temp[27]),
41 + buf28(data[28],temp[28]),
42 + buf29(data[29],temp[29]),
43 + buf30(data[30],temp[30]),
44 + buf31(data[31],temp[31]);
45 +
46 +always @(posedge clk)
47 + if (writeenable)
48 + begin
49 + datamem[address]=writedata[31:24];
50 + datamem[address+1]=writedata[23:16];
51 + datamem[address+2]=writedata[15:8];
52 + datamem[address+3]=writedata[7:0];
53 + end
54 +
55 +always @(address or datamem[address] or datamem[address+1] or datamem[address+2] or datamem[address+3])
56 +begin
57 + temp={datamem[address],datamem[address+1],datamem[address+2],datamem[address+3]};
58 +end
59 +
60 +// initial
61 +// begin
62 +// $readmemh("data.dat", datamem);
63 +// end
64 +
65 +endmodule
1 +module dec5to32(Out,Adr);
2 +input [4:0] Adr; // Adr=Address of register
3 +output [31:0] Out;
4 +not #(50) Inv4(Nota, Adr[4]);
5 +not #(50) Inv3(Notb, Adr[3]);
6 +not #(50) Inv2(Notc, Adr[2]);
7 +not #(50) Inv1(Notd, Adr[1]);
8 +not #(50) Inv0(Note, Adr[0]);
9 +
10 +andmore a0(Out[0], Nota,Notb,Notc,Notd,Note); // 00000
11 +andmore a1(Out[1], Nota,Notb,Notc,Notd,Adr[0]); // 00001
12 +andmore a2(Out[2], Nota,Notb,Notc,Adr[1],Note); //00010
13 +andmore a3(Out[3], Nota,Notb,Notc,Adr[1],Adr[0]);
14 +andmore a4(Out[4], Nota,Notb,Adr[2],Notd,Note);
15 +andmore a5(Out[5], Nota,Notb,Adr[2],Notd,Adr[0]);
16 +andmore a6(Out[6], Nota,Notb,Adr[2],Adr[1],Note);
17 +andmore a7(Out[7], Nota,Notb,Adr[2],Adr[1],Adr[0]);
18 +andmore a8(Out[8], Nota,Adr[3],Notc,Notd,Note);
19 +andmore a9(Out[9], Nota,Adr[3],Notc,Notd,Adr[0]);
20 +andmore a10(Out[10], Nota,Adr[3],Notc,Adr[1],Note);
21 +andmore a11(Out[11], Nota,Adr[3],Notc,Adr[1],Adr[0]);
22 +andmore a12(Out[12], Nota,Adr[3],Adr[2],Notd,Note);
23 +andmore a13(Out[13], Nota,Adr[3],Adr[2],Notd,Adr[0]);
24 +andmore a14(Out[14], Nota,Adr[3],Adr[2],Adr[1],Note);
25 +andmore a15(Out[15], Nota,Adr[3],Adr[2],Adr[1],Adr[0]);
26 +andmore a16(Out[16], Adr[4],Notb,Notc,Notd,Note);
27 +andmore a17(Out[17], Adr[4],Notb,Notc,Notd,Adr[0]);
28 +andmore a18(Out[18], Adr[4],Notb,Notc,Adr[1],Note);
29 +andmore a19(Out[19], Adr[4],Notb,Notc,Adr[1],Adr[0]);
30 +andmore a20(Out[20], Adr[4],Notb,Adr[2],Notd,Note);
31 +andmore a21(Out[21], Adr[4],Notb,Adr[2],Notd,Adr[0]);
32 +andmore a22(Out[22], Adr[4],Notb,Adr[2],Adr[1],Note);
33 +andmore a23(Out[23], Adr[4],Notb,Adr[2],Adr[1],Adr[0]);
34 +andmore a24(Out[24], Adr[4],Adr[3],Notc,Notd,Note);
35 +andmore a25(Out[25], Adr[4],Adr[3],Notc,Notd,Adr[0]);
36 +andmore a26(Out[26], Adr[4],Adr[3],Notc,Adr[1],Note);
37 +andmore a27(Out[27], Adr[4],Adr[3],Notc,Adr[1],Adr[0]);
38 +andmore a28(Out[28], Adr[4],Adr[3],Adr[2],Notd,Note);
39 +andmore a29(Out[29], Adr[4],Adr[3],Adr[2],Notd,Adr[0]);
40 +andmore a30(Out[30], Adr[4],Adr[3],Adr[2],Adr[1],Note);
41 +andmore a31(Out[31], Adr[4],Adr[3],Adr[2],Adr[1],Adr[0]); // 11111
42 +endmodule
1 +module decoder(WriteEn,RegWrite, WriteRegister);
2 +input RegWrite;
3 +input [4:0] WriteRegister;
4 +output [31:0] WriteEn;
5 +wire [31:0] OE; // Output Enable
6 +dec5to32 dec(OE,WriteRegister);
7 +assign WriteEn[0]=0;
8 + and #(50) gate1(WriteEn[1],OE[1],RegWrite);
9 + and #(50) gate2(WriteEn[2],OE[2],RegWrite);
10 + and #(50) gate3(WriteEn[3],OE[3],RegWrite);
11 + and #(50) gate4(WriteEn[4],OE[4],RegWrite);
12 + and #(50) gate5(WriteEn[5],OE[5],RegWrite);
13 + and #(50) gate6(WriteEn[6],OE[6],RegWrite);
14 + and #(50) gate7(WriteEn[7],OE[7],RegWrite);
15 + and #(50) gate8(WriteEn[8],OE[8],RegWrite);
16 + and #(50) gate9(WriteEn[9],OE[9],RegWrite);
17 + and #(50) gate10(WriteEn[10],OE[10],RegWrite);
18 + and #(50) gate11(WriteEn[11],OE[11],RegWrite);
19 + and #(50) gate12(WriteEn[12],OE[12],RegWrite);
20 + and #(50) gate13(WriteEn[13],OE[13],RegWrite);
21 + and #(50) gate14(WriteEn[14],OE[14],RegWrite);
22 + and #(50) gate15(WriteEn[15],OE[15],RegWrite);
23 + and #(50) gate16(WriteEn[16],OE[16],RegWrite);
24 + and #(50) gate17(WriteEn[17],OE[17],RegWrite);
25 + and #(50) gate18(WriteEn[18],OE[18],RegWrite);
26 + and #(50) gate19(WriteEn[19],OE[19],RegWrite);
27 + and #(50) gate20(WriteEn[20],OE[20],RegWrite);
28 + and #(50) gate21(WriteEn[21],OE[21],RegWrite);
29 + and #(50) gate22(WriteEn[22],OE[22],RegWrite);
30 + and #(50) gate23(WriteEn[23],OE[23],RegWrite);
31 + and #(50) gate24(WriteEn[24],OE[24],RegWrite);
32 + and #(50) gate25(WriteEn[25],OE[25],RegWrite);
33 + and #(50) gate26(WriteEn[26],OE[26],RegWrite);
34 + and #(50) gate27(WriteEn[27],OE[27],RegWrite);
35 + and #(50) gate28(WriteEn[28],OE[28],RegWrite);
36 + and #(50) gate29(WriteEn[29],OE[29],RegWrite);
37 + and #(50) gate30(WriteEn[30],OE[30],RegWrite);
38 + and #(50) gate31(WriteEn[31],OE[31],RegWrite);
39 +endmodule
40 +module andmore(g,a,b,c,d,e);
41 + output g;
42 + input a,b,c,d,e;
43 + and #(50) and1(f1,a,b,c,d),
44 + and2(g,f1,e);
45 +endmodule
46 +module dec5to32(Out,Adr);
47 +input [4:0] Adr; // Adr=Address of register
48 +output [31:0] Out;
49 +not #(50) Inv4(Nota, Adr[4]);
50 +not #(50) Inv3(Notb, Adr[3]);
51 +not #(50) Inv2(Notc, Adr[2]);
52 +not #(50) Inv1(Notd, Adr[1]);
53 +not #(50) Inv0(Note, Adr[0]);
54 +
55 +andmore a0(Out[0], Nota,Notb,Notc,Notd,Note); // 00000
56 +andmore a1(Out[1], Nota,Notb,Notc,Notd,Adr[0]); // 00001
57 +andmore a2(Out[2], Nota,Notb,Notc,Adr[1],Note); //00010
58 +andmore a3(Out[3], Nota,Notb,Notc,Adr[1],Adr[0]);
59 +andmore a4(Out[4], Nota,Notb,Adr[2],Notd,Note);
60 +andmore a5(Out[5], Nota,Notb,Adr[2],Notd,Adr[0]);
61 +andmore a6(Out[6], Nota,Notb,Adr[2],Adr[1],Note);
62 +andmore a7(Out[7], Nota,Notb,Adr[2],Adr[1],Adr[0]);
63 +andmore a8(Out[8], Nota,Adr[3],Notc,Notd,Note);
64 +andmore a9(Out[9], Nota,Adr[3],Notc,Notd,Adr[0]);
65 +andmore a10(Out[10], Nota,Adr[3],Notc,Adr[1],Note);
66 +andmore a11(Out[11], Nota,Adr[3],Notc,Adr[1],Adr[0]);
67 +andmore a12(Out[12], Nota,Adr[3],Adr[2],Notd,Note);
68 +andmore a13(Out[13], Nota,Adr[3],Adr[2],Notd,Adr[0]);
69 +andmore a14(Out[14], Nota,Adr[3],Adr[2],Adr[1],Note);
70 +andmore a15(Out[15], Nota,Adr[3],Adr[2],Adr[1],Adr[0]);
71 +andmore a16(Out[16], Adr[4],Notb,Notc,Notd,Note);
72 +andmore a17(Out[17], Adr[4],Notb,Notc,Notd,Adr[0]);
73 +andmore a18(Out[18], Adr[4],Notb,Notc,Adr[1],Note);
74 +andmore a19(Out[19], Adr[4],Notb,Notc,Adr[1],Adr[0]);
75 +andmore a20(Out[20], Adr[4],Notb,Adr[2],Notd,Note);
76 +andmore a21(Out[21], Adr[4],Notb,Adr[2],Notd,Adr[0]);
77 +andmore a22(Out[22], Adr[4],Notb,Adr[2],Adr[1],Note);
78 +andmore a23(Out[23], Adr[4],Notb,Adr[2],Adr[1],Adr[0]);
79 +andmore a24(Out[24], Adr[4],Adr[3],Notc,Notd,Note);
80 +andmore a25(Out[25], Adr[4],Adr[3],Notc,Notd,Adr[0]);
81 +andmore a26(Out[26], Adr[4],Adr[3],Notc,Adr[1],Note);
82 +andmore a27(Out[27], Adr[4],Adr[3],Notc,Adr[1],Adr[0]);
83 +andmore a28(Out[28], Adr[4],Adr[3],Adr[2],Notd,Note);
84 +andmore a29(Out[29], Adr[4],Adr[3],Adr[2],Notd,Adr[0]);
85 +andmore a30(Out[30], Adr[4],Adr[3],Adr[2],Adr[1],Note);
86 +andmore a31(Out[31], Adr[4],Adr[3],Adr[2],Adr[1],Adr[0]); // 11111
87 +endmodule
1 +C:/Modeltech_pe_edu_10.4a/finalproject/shift_left_2.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/shift_left_2.v
2 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
3 +-- Compiling module sign_extend
4 +-- Compiling module shift_left_2
5 +
6 +Top level modules:
7 + sign_extend
8 + shift_left_2
9 +
10 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/StallControl.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/StallControl.v
11 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
12 +-- Compiling module StallControl
13 +
14 +Top level modules:
15 + StallControl
16 +
17 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/dataMem.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/dataMem.v
18 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
19 +-- Compiling module dataMem
20 +
21 +Top level modules:
22 + dataMem
23 +
24 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/Control.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/Control.v
25 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
26 +-- Compiling module Control
27 +
28 +Top level modules:
29 + Control
30 +
31 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/mux3x32to32.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/mux3x32to32.v
32 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
33 +-- Compiling module mux3x32to32
34 +
35 +Top level modules:
36 + mux3x32to32
37 +
38 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/alu.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/alu.v
39 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
40 +-- Compiling module alu
41 +-- Compiling module alu1bit
42 +-- Compiling module addsub
43 +-- Compiling module adder
44 +-- Compiling module mux21
45 +
46 +Top level modules:
47 + alu
48 +
49 +} {} {}} {C:/Modeltech_pe_edu_10.4a/finalproject/Forwarding Unit.v} {1 {vlog -work work -stats=none {C:/Modeltech_pe_edu_10.4a/finalproject/Forwarding Unit.v}
50 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
51 +-- Compiling module ForwardingUnit
52 +
53 +Top level modules:
54 + ForwardingUnit
55 +
56 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/mux32to1.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/mux32to1.v
57 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
58 +-- Compiling module mux32to1
59 +
60 +Top level modules:
61 + mux32to1
62 +
63 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/flush_block.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/flush_block.v
64 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
65 +-- Compiling module flush_block
66 +-- Compiling module Discard_Instr
67 +
68 +Top level modules:
69 + flush_block
70 + Discard_Instr
71 +
72 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/regfile.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/regfile.v
73 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
74 +-- Compiling module regfile
75 +
76 +Top level modules:
77 + regfile
78 +
79 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/MIPSpipeline.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/MIPSpipeline.v
80 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
81 +-- Compiling module MIPSpipeline
82 +
83 +Top level modules:
84 + MIPSpipeline
85 +
86 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/MIPSStimulus.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/MIPSStimulus.v
87 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
88 +-- Compiling module MIPSStimulus
89 +
90 +Top level modules:
91 + MIPSStimulus
92 +
93 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/JRControl_Block.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/JRControl_Block.v
94 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
95 +-- Compiling module JRControl_Block
96 +
97 +Top level modules:
98 + JRControl_Block
99 +
100 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/sign_extend.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/sign_extend.v
101 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
102 +-- Compiling module sign_extend
103 +-- Compiling module shift_left_2
104 +
105 +Top level modules:
106 + sign_extend
107 + shift_left_2
108 +
109 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/adder1bit.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/adder1bit.v
110 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
111 +-- Compiling module adder1bit
112 +
113 +Top level modules:
114 + adder1bit
115 +
116 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/mux2x5to5.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/mux2x5to5.v
117 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
118 +-- Compiling module mux2x5to5
119 +-- Compiling module mux2_1
120 +
121 +Top level modules:
122 + mux2x5to5
123 + mux2_1
124 +
125 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/mux2x32to32.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/mux2x32to32.v
126 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
127 +-- Compiling module mux2x32to32
128 +
129 +Top level modules:
130 + mux2x32to32
131 +
132 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/InstructionMem.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/InstructionMem.v
133 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
134 +-- Compiling module InstructionMem
135 +-- Compiling module instrmemstimulous
136 +
137 +Top level modules:
138 + instrmemstimulous
139 +
140 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/Add.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/Add.v
141 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
142 +-- Compiling module Add
143 +
144 +Top level modules:
145 + Add
146 +
147 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/dec5to32.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/dec5to32.v
148 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
149 +-- Compiling module dec5to32
150 +
151 +Top level modules:
152 + dec5to32
153 +
154 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/mux32x32to32.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/mux32x32to32.v
155 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
156 +-- Compiling module mux32x32to32
157 +
158 +Top level modules:
159 + mux32x32to32
160 +
161 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/ALUControl_Block.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/ALUControl_Block.v
162 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
163 +-- Compiling module ALUControl_Block
164 +
165 +Top level modules:
166 + ALUControl_Block
167 +
168 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/WB_forward.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/WB_forward.v
169 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
170 +-- Compiling module WB_forward
171 +-- Compiling module CompareAddress
172 +
173 +Top level modules:
174 + WB_forward
175 +
176 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/RegBit.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/RegBit.v
177 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
178 +-- Compiling module RegBit
179 +
180 +Top level modules:
181 + RegBit
182 +
183 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/register.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/register.v
184 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
185 +-- Compiling module register
186 +
187 +Top level modules:
188 + register
189 +
190 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/decoder.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/decoder.v
191 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
192 +-- Compiling module decoder
193 +-- Compiling module andmore
194 +-- Compiling module dec5to32
195 +
196 +Top level modules:
197 + decoder
198 +
199 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/andmore.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/andmore.v
200 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
201 +-- Compiling module andmore
202 +
203 +Top level modules:
204 + andmore
205 +
206 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/zero_extend.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/zero_extend.v
207 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
208 +-- Compiling module zero_extend
209 +
210 +Top level modules:
211 + zero_extend
212 +
213 +} {} {}} C:/Modeltech_pe_edu_10.4a/finalproject/D_FF.v {1 {vlog -work work -stats=none C:/Modeltech_pe_edu_10.4a/finalproject/D_FF.v
214 +Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
215 +-- Compiling module D_FF
216 +
217 +Top level modules:
218 + D_FF
219 +
220 +} {} {}}
This diff could not be displayed because it is too large.
1 +// FPGA projects, Verilog Projects, VHDL projects
2 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
3 +// Flush control signals
4 +`timescale 1 ps / 100 fs
5 +module flush_block(
6 +ID_RegDst,ID_ALUSrc, ID_MemtoReg,ID_RegWrite,ID_MemRead,ID_MemWrite,
7 +ID_Branch,ID_ALUOp,ID_JRControl,flush,RegDst,ALUSrc,MemtoReg,RegWrite,
8 +MemRead,MemWrite,Branch,ALUOp,JRControl);
9 +
10 +output ID_RegDst,ID_ALUSrc,ID_MemtoReg,ID_RegWrite,ID_MemRead,ID_MemWrite,ID_Branch,ID_JRControl;
11 +output [1:0] ID_ALUOp;
12 +input flush,RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,JRControl;
13 +input [1:0] ALUOp;
14 +
15 +not #50 (notflush,flush);
16 +and #50 and1(ID_RegDst,RegDst,notflush);
17 +and #50 and2(ID_ALUSrc,ALUSrc,notflush);
18 +and #50 and3(ID_MemtoReg,MemtoReg,notflush);
19 +and #50 and4(ID_RegWrite,RegWrite,notflush);
20 +and #50 and5(ID_MemRead,MemRead,notflush);
21 +and #50 and6(ID_MemWrite,MemWrite,notflush);
22 +and #50 and7(ID_Branch,Branch,notflush);
23 +and #50 and8(ID_JRControl,JRControl,notflush);
24 +and #50 and9(ID_ALUOp[1],ALUOp[1],notflush);
25 +and #50 and10(ID_ALUOp[0],ALUOp[0],notflush);
26 +endmodule
27 +`timescale 1 ps / 100 fs
28 +// fpga4student.com: FPGA projects, Verilog Projects, VHDL projects
29 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
30 +// Discard instructions when needed
31 +module Discard_Instr(ID_flush,IF_flush,jump,bne,jr);
32 +output ID_flush,IF_flush;
33 +input jump,bne,jr;
34 +or #50 OR1(IF_flush,jump,bne,jr);
35 +or #50 OR2(ID_flush,bne,jr);
36 +endmodule
1 +00111000000100000000000000000011
2 +00111000000100010000000000000100
3 +00001000000000000000000000000101
4 +00111000000100000000000000000001
5 +00111000000100010000000000000001
6 +00000010001100001001000000100010
7 +00010110000100011111111111111100
8 +00000010000100011001100000100000
9 +10101110010100110000000000010000
10 +10001110010101000000000000010000
11 +00000010000101001010100000101010
12 +10001110010100110000000000010000
13 +00111010010100110000000000000001
14 +00111010101101010000000000000001
15 +00000010101000000000000000001000
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// mux2x32to32
5 +module mux2x32to32( DataOut,Data0, Data1, Select);
6 +output [31:0] DataOut; // Data Out
7 +input [31:0] Data0, Data1; // Data In 1 and 2
8 +input Select;
9 +// neu Select = 0 thi DataOut = Data0
10 +// nguoc lai thi DataOut = Data1
11 +
12 +mux2_1 mux0(DataOut[0],Data0[0],Data1[0],Select);
13 +mux2_1 mux1(DataOut[1],Data0[1],Data1[1],Select);
14 +mux2_1 mux2(DataOut[2],Data0[2],Data1[2],Select);
15 +mux2_1 mux3(DataOut[3],Data0[3],Data1[3],Select);
16 +mux2_1 mux4(DataOut[4],Data0[4],Data1[4],Select);
17 +mux2_1 mux5(DataOut[5],Data0[5],Data1[5],Select);
18 +mux2_1 mux6(DataOut[6],Data0[6],Data1[6],Select);
19 +mux2_1 mux7(DataOut[7],Data0[7],Data1[7],Select);
20 +mux2_1 mux8(DataOut[8],Data0[8],Data1[8],Select);
21 +mux2_1 mux9(DataOut[9],Data0[9],Data1[9],Select);
22 +mux2_1 mux10(DataOut[10],Data0[10],Data1[10],Select);
23 +mux2_1 mux11(DataOut[11],Data0[11],Data1[11],Select);
24 +mux2_1 mux12(DataOut[12],Data0[12],Data1[12],Select);
25 +mux2_1 mux13(DataOut[13],Data0[13],Data1[13],Select);
26 +mux2_1 mux14(DataOut[14],Data0[14],Data1[14],Select);
27 +mux2_1 mux15(DataOut[15],Data0[15],Data1[15],Select);
28 +mux2_1 mux16(DataOut[16],Data0[16],Data1[16],Select);
29 +mux2_1 mux17(DataOut[17],Data0[17],Data1[17],Select);
30 +mux2_1 mux18(DataOut[18],Data0[18],Data1[18],Select);
31 +mux2_1 mux19(DataOut[19],Data0[19],Data1[19],Select);
32 +mux2_1 mux20(DataOut[20],Data0[20],Data1[20],Select);
33 +mux2_1 mux21(DataOut[21],Data0[21],Data1[21],Select);
34 +mux2_1 mux22(DataOut[22],Data0[22],Data1[22],Select);
35 +mux2_1 mux23(DataOut[23],Data0[23],Data1[23],Select);
36 +mux2_1 mux24(DataOut[24],Data0[24],Data1[24],Select);
37 +mux2_1 mux25(DataOut[25],Data0[25],Data1[25],Select);
38 +mux2_1 mux26(DataOut[26],Data0[26],Data1[26],Select);
39 +mux2_1 mux27(DataOut[27],Data0[27],Data1[27],Select);
40 +mux2_1 mux28(DataOut[28],Data0[28],Data1[28],Select);
41 +mux2_1 mux29(DataOut[29],Data0[29],Data1[29],Select);
42 +mux2_1 mux30(DataOut[30],Data0[30],Data1[30],Select);
43 +mux2_1 mux31(DataOut[31],Data0[31],Data1[31],Select);
44 +
45 +endmodule
1 +`timescale 1 ps / 100 fs
2 +//: FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// mux2x5to5
5 +// Select Write Register
6 +module mux2x5to5( AddrOut,Addr0, Addr1, Select);
7 +output [4:0] AddrOut; // Address Out
8 +input [4:0] Addr0, Addr1; // Address In 1 and 2
9 +input Select;
10 +mux21 mux0(AddrOut[0],Addr0[0],Addr1[0],Select);
11 +mux21 mux1(AddrOut[1],Addr0[1],Addr1[1],Select);
12 +mux21 mux2(AddrOut[2],Addr0[2],Addr1[2],Select);
13 +mux21 mux3(AddrOut[3],Addr0[3],Addr1[3],Select);
14 +mux21 mux4(AddrOut[4],Addr0[4],Addr1[4],Select);
15 +endmodule
16 +module mux2_1(O,A,B,sel);
17 +// sel = 0 : O = A
18 +// sel = 1 : O =B
19 +output O;
20 +input A,B,sel;
21 +not #(50) not1(nsel,sel);
22 +and #(50) and1(O1,A,nsel);
23 +and #(50) and2(O2,B,sel);
24 +or #(50) or2(O,O1,O2);
25 +endmodule
1 +//------------module multiplexor 32 to 1----------------
2 +module mux32to1(Out, In , Select);
3 +output Out;
4 +input [31:0] In;
5 +input [4:0] Select;
6 +wire [31:0] OE,f; // OE = Output Enable
7 +dec5to32 dec1(OE,Select);
8 +
9 + and #(50) g_0(f[0],OE[0],In[0]);
10 + and #(50) g_1(f[1],OE[1],In[1]);
11 + and #(50) g_2(f[2],OE[2],In[2]);
12 + and #(50) g_3(f[3],OE[3],In[3]);
13 + and #(50) g_4(f[4],OE[4],In[4]);
14 + and #(50) g_5(f[5],OE[5],In[5]);
15 + and #(50) g_6(f[6],OE[6],In[6]);
16 + and #(50) g_7(f[7],OE[7],In[7]);
17 + and #(50) g_8(f[8],OE[8],In[8]);
18 + and #(50) g_9(f[9],OE[9],In[9]);
19 + and #(50) g_10(f[10],OE[10],In[10]);
20 + and #(50) g_11(f[11],OE[11],In[11]);
21 + and #(50) g_12(f[12],OE[12],In[12]);
22 + and #(50) g_13(f[13],OE[13],In[13]);
23 + and #(50) g_14(f[14],OE[14],In[14]);
24 + and #(50) g_15(f[15],OE[15],In[15]);
25 + and #(50) g_16(f[16],OE[16],In[16]);
26 + and #(50) g_17(f[17],OE[17],In[17]);
27 + and #(50) g_18(f[18],OE[18],In[18]);
28 + and #(50) g_19(f[19],OE[19],In[19]);
29 + and #(50) g_20(f[20],OE[20],In[20]);
30 + and #(50) g_21(f[21],OE[21],In[21]);
31 + and #(50) g_22(f[22],OE[22],In[22]);
32 + and #(50) g_23(f[23],OE[23],In[23]);
33 + and #(50) g_24(f[24],OE[24],In[24]);
34 + and #(50) g_25(f[25],OE[25],In[25]);
35 + and #(50) g_26(f[26],OE[26],In[26]);
36 + and #(50) g_27(f[27],OE[27],In[27]);
37 + and #(50) g_28(f[28],OE[28],In[28]);
38 + and #(50) g_29(f[29],OE[29],In[29]);
39 + and #(50) g_30(f[30],OE[30],In[30]);
40 + and #(50) g_31(f[31],OE[31],In[31]);
41 +
42 +
43 +
44 + or #(50) gate3(g3,f[0],f[1],f[2],f[3]);
45 + or #(50) gate4(g4,f[4],f[5],f[6],f[7]);
46 + or #(50) gate5(g5,f[8],f[9],f[10],f[11]);
47 + or #(50) gate6(g6,f[12],f[13],f[14],f[15]);
48 + or #(50) gate7(g7,f[16],f[17],f[18],f[19]);
49 + or #(50) gate8(g8,f[20],f[21],f[22],f[23]);
50 + or #(50) gate9(g9,f[24],f[25],f[26],f[27]);
51 + or #(50) gate10(g10,f[28],f[29],f[30],f[31]);
52 + or #(50) gate11(g11,g3,g4,g5,g6);
53 + or #(50) gate12(g12,g7,g8,g9,10);
54 + or #(50) gate(Out,g11,g12);
55 + endmodule
1 +module mux32x32to32(ReadData,In0, In1,In2,In3,In4,In5,In6,In7,In8,In9,In10,In11,In12,In13,In14,In15,In16,In17,In18,In19,In20,In21,In22,In23, In24,In25,In26,In27,In28,In29,In30,In31,ReadRegister);
2 +
3 +input [31:0] In0, In1,In2,In3,In4,In5,In6,In7,In8,In9,In10,In11,In12,In13,In14,In15,In16,In17,In18,In19,In20,In21,In22,In23,In24,In25,In26,In27,In28,In29,In30,In31;
4 +input [4:0] ReadRegister;
5 +output [31:0] ReadData;
6 +reg [31:0] ArrayReg [0:31];
7 +integer j;
8 +always @(*)
9 +begin
10 +for (j=0;j<=31;j=j+1)
11 + ArrayReg[j] = {In31[j], In30[j],In29[j],In28[j],In27[j],In26[j],In25[j],In24[j],In23[j],In22[j],In21[j],
12 + In20[j],In19[j],In18[j],In17[j],In16[j],In15[j],In14[j],In13[j],In12[j],In11[j],
13 + In10[j],In9[j],In8[j],In7[j],In6[j],In5[j],In4[j],In3[j],In2[j],In1[j],In0[j]};
14 +
15 +end
16 +mux32to1 mux0(ReadData[0],ArrayReg[0],ReadRegister);
17 +mux32to1 mux1(ReadData[1],ArrayReg[1],ReadRegister);
18 +mux32to1 mux2(ReadData[2],ArrayReg[2],ReadRegister);
19 +mux32to1 mux3(ReadData[3],ArrayReg[3],ReadRegister);
20 +mux32to1 mux4(ReadData[4],ArrayReg[4],ReadRegister);
21 +mux32to1 mux5(ReadData[5],ArrayReg[5],ReadRegister);
22 +mux32to1 mux6(ReadData[6],ArrayReg[6],ReadRegister);
23 +mux32to1 mux7(ReadData[7],ArrayReg[7],ReadRegister);
24 +mux32to1 mux8(ReadData[8],ArrayReg[8],ReadRegister);
25 +mux32to1 mux9(ReadData[9],ArrayReg[9],ReadRegister);
26 +mux32to1 mux10(ReadData[10],ArrayReg[10],ReadRegister);
27 +mux32to1 mux11(ReadData[11],ArrayReg[11],ReadRegister);
28 +mux32to1 mux12(ReadData[12],ArrayReg[12],ReadRegister);
29 +mux32to1 mux13(ReadData[13],ArrayReg[13],ReadRegister);
30 +mux32to1 mux14(ReadData[14],ArrayReg[14],ReadRegister);
31 +mux32to1 mux15(ReadData[15],ArrayReg[15],ReadRegister);
32 +mux32to1 mux16(ReadData[16],ArrayReg[16],ReadRegister);
33 +mux32to1 mux17(ReadData[17],ArrayReg[17],ReadRegister);
34 +mux32to1 mux18(ReadData[18],ArrayReg[18],ReadRegister);
35 +mux32to1 mux19(ReadData[19],ArrayReg[19],ReadRegister);
36 +mux32to1 mux20(ReadData[20],ArrayReg[20],ReadRegister);
37 +mux32to1 mux21(ReadData[21],ArrayReg[21],ReadRegister);
38 +mux32to1 mux22(ReadData[22],ArrayReg[22],ReadRegister);
39 +mux32to1 mux23(ReadData[23],ArrayReg[23],ReadRegister);
40 +mux32to1 mux24(ReadData[24],ArrayReg[24],ReadRegister);
41 +mux32to1 mux25(ReadData[25],ArrayReg[25],ReadRegister);
42 +mux32to1 mux26(ReadData[26],ArrayReg[26],ReadRegister);
43 +mux32to1 mux27(ReadData[27],ArrayReg[27],ReadRegister);
44 +mux32to1 mux28(ReadData[28],ArrayReg[28],ReadRegister);
45 +mux32to1 mux29(ReadData[29],ArrayReg[29],ReadRegister);
46 +mux32to1 mux30(ReadData[30],ArrayReg[30],ReadRegister);
47 +mux32to1 mux31(ReadData[31],ArrayReg[31],ReadRegister);
48 +
49 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// mux3x32to32
5 +module mux3x32to32(DataOut,A,B,C,Select);
6 +output [31:0] DataOut;
7 +input [1:0] Select;
8 +input [31:0] A,B,C;
9 +wire [31:0] DataOut1,DataOut2;
10 +
11 +mux2x32to32 muxAB(DataOut1,A,B, Select[1]);
12 +mux2x32to32 muxCA(DataOut2,C,A, Select[1]);
13 +mux2x32to32 muxABC(DataOut,DataOut1,DataOut2, Select[0]);
14 +
15 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// fpga4student.com: FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Register file
5 +module regfile(
6 +ReadData1,
7 +ReadData2,
8 +WriteData,
9 +ReadRegister1,
10 +ReadRegister2,
11 +WriteRegister,
12 +RegWrite,
13 +reset,
14 +clk);
15 +
16 +input [4:0]ReadRegister1,ReadRegister2,WriteRegister;
17 +input [31:0] WriteData;
18 +input RegWrite,reset, clk;
19 +output [31:0] ReadData1, ReadData2;
20 +wire [31:0] WriteEn;
21 +wire [31:0] RegArray [0:31];
22 +integer i;
23 + //----Decoder Block
24 + decoder Decoder1( WriteEn,RegWrite,WriteRegister);
25 + register reg0 (RegArray[0],32'b0,1'b1,1'b0, clk);
26 + register reg1 (RegArray[1],WriteData,WriteEn[1],reset,clk);
27 + register reg2 (RegArray[2],WriteData,WriteEn[2],reset,clk);
28 + register reg3 (RegArray[3],WriteData,WriteEn[3],reset,clk);
29 + register reg4 (RegArray[4],WriteData,WriteEn[4],reset,clk);
30 + register reg5 (RegArray[5],WriteData,WriteEn[5],reset,clk);
31 + register reg6 (RegArray[6],WriteData,WriteEn[6],reset,clk);
32 + register reg7 (RegArray[7],WriteData,WriteEn[7],reset,clk);
33 + register reg8 (RegArray[8],WriteData,WriteEn[8],reset,clk);
34 + register reg9 (RegArray[9],WriteData,WriteEn[9],reset,clk);
35 + register reg10 (RegArray[10],WriteData,WriteEn[10],reset,clk);
36 + register reg11 (RegArray[11],WriteData,WriteEn[11],reset,clk);
37 + register reg12 (RegArray[12],WriteData,WriteEn[12],reset,clk);
38 + register reg13 (RegArray[13],WriteData,WriteEn[13],reset,clk);
39 + register reg14 (RegArray[14],WriteData,WriteEn[14],reset,clk);
40 + register reg15 (RegArray[15],WriteData,WriteEn[15],reset,clk);
41 + register reg16 (RegArray[16],WriteData,WriteEn[16],reset,clk);
42 + register reg17 (RegArray[17],WriteData,WriteEn[17],reset,clk);
43 + register reg18 (RegArray[18],WriteData,WriteEn[18],reset,clk);
44 + register reg19 (RegArray[19],WriteData,WriteEn[19],reset,clk);
45 + register reg20 (RegArray[20],WriteData,WriteEn[20],reset,clk);
46 + register reg21 (RegArray[21],WriteData,WriteEn[21],reset,clk);
47 + register reg22 (RegArray[22],WriteData,WriteEn[22],reset,clk);
48 + register reg23 (RegArray[23],WriteData,WriteEn[23],reset,clk);
49 + register reg24 (RegArray[24],WriteData,WriteEn[24],reset,clk);
50 + register reg25 (RegArray[25],WriteData,WriteEn[25],reset,clk);
51 + register reg26 (RegArray[26],WriteData,WriteEn[26],reset,clk);
52 + register reg27 (RegArray[27],WriteData,WriteEn[27],reset,clk);
53 + register reg28 (RegArray[28],WriteData,WriteEn[28],reset,clk);
54 + register reg29 (RegArray[29],WriteData,WriteEn[29],reset,clk);
55 + register reg30 (RegArray[30],WriteData,WriteEn[30],reset,clk);
56 + register reg31 (RegArray[31],WriteData,WriteEn[31],reset,clk);
57 + //----32x32to32 Multiplexor1 Block----
58 + mux32x32to32 Mux1(ReadData1,RegArray[0], RegArray[1],RegArray[2], RegArray[3],RegArray[4],RegArray[5],RegArray[6],RegArray[7],
59 + RegArray[8],RegArray[9],RegArray[10],RegArray[11],RegArray[12],RegArray[13],RegArray[14],RegArray[15],RegArray[16],RegArray[17],
60 + RegArray[18], RegArray[19],RegArray[20],RegArray[21],RegArray[22],RegArray[23],RegArray[24],RegArray[25],RegArray[26],
61 + RegArray[27], RegArray[28], RegArray[29],RegArray[30],RegArray[31], ReadRegister1
62 + );
63 +
64 + //----32x32to32 Multiplexor2 Block----
65 + mux32x32to32 Mux2(ReadData2,RegArray[0], RegArray[1],RegArray[2], RegArray[3],RegArray[4],RegArray[5],RegArray[6],RegArray[7],
66 + RegArray[8],RegArray[9],RegArray[10],RegArray[11],RegArray[12],RegArray[13],RegArray[14],RegArray[15],RegArray[16],RegArray[17],
67 + RegArray[18], RegArray[19],RegArray[20],RegArray[21],RegArray[22],RegArray[23],RegArray[24],RegArray[25],RegArray[26],
68 + RegArray[27], RegArray[28], RegArray[29],RegArray[30],RegArray[31], ReadRegister2
69 + );
70 +endmodule
1 +//32 bit register
2 +module register(RegOut,RegIn,WriteEn,reset,clk);
3 +output [31:0] RegOut;
4 +input [31:0] RegIn;
5 +input WriteEn,reset, clk;
6 +RegBit bit31(RegOut[31],RegIn[31],WriteEn,reset,clk);
7 +RegBit bit30(RegOut[30],RegIn[30],WriteEn,reset,clk);
8 +RegBit bit29(RegOut[29],RegIn[29],WriteEn,reset,clk);
9 +RegBit bit28(RegOut[28],RegIn[28],WriteEn,reset,clk);
10 +RegBit bit27(RegOut[27],RegIn[27],WriteEn,reset,clk);
11 +RegBit bit26(RegOut[26],RegIn[26],WriteEn,reset,clk);
12 +RegBit bit25(RegOut[25],RegIn[25],WriteEn,reset,clk);
13 +RegBit bit24(RegOut[24],RegIn[24],WriteEn,reset,clk);
14 +RegBit bit23(RegOut[23],RegIn[23],WriteEn,reset,clk);
15 +RegBit bit22(RegOut[22],RegIn[22],WriteEn,reset,clk);
16 +RegBit bit21(RegOut[21],RegIn[21],WriteEn,reset,clk);
17 +RegBit bit20(RegOut[20],RegIn[20],WriteEn,reset,clk);
18 +RegBit bit19(RegOut[19],RegIn[19],WriteEn,reset,clk);
19 +RegBit bit18(RegOut[18],RegIn[18],WriteEn,reset,clk);
20 +RegBit bit17(RegOut[17],RegIn[17],WriteEn,reset,clk);
21 +RegBit bit16(RegOut[16],RegIn[16],WriteEn,reset,clk);
22 +RegBit bit15(RegOut[15],RegIn[15],WriteEn,reset,clk);
23 +RegBit bit14(RegOut[14],RegIn[14],WriteEn,reset,clk);
24 +RegBit bit13(RegOut[13],RegIn[13],WriteEn,reset,clk);
25 +RegBit bit12(RegOut[12],RegIn[12],WriteEn,reset,clk);
26 +RegBit bit11(RegOut[11],RegIn[11],WriteEn,reset,clk);
27 +RegBit bit10(RegOut[10],RegIn[10],WriteEn,reset,clk);
28 +RegBit bit9 (RegOut[9], RegIn[9], WriteEn,reset,clk);
29 +RegBit bit8 (RegOut[8], RegIn[8], WriteEn,reset,clk);
30 +RegBit bit7 (RegOut[7], RegIn[7], WriteEn,reset,clk);
31 +RegBit bit6 (RegOut[6], RegIn[6], WriteEn,reset,clk);
32 +RegBit bit5 (RegOut[5], RegIn[5], WriteEn,reset,clk);
33 +RegBit bit4 (RegOut[4], RegIn[4], WriteEn,reset,clk);
34 +RegBit bit3 (RegOut[3], RegIn[3], WriteEn,reset,clk);
35 +RegBit bit2 (RegOut[2], RegIn[2], WriteEn,reset,clk);
36 +RegBit bit1 (RegOut[1], RegIn[1], WriteEn,reset,clk);
37 +RegBit bit0 (RegOut[0], RegIn[0], WriteEn,reset,clk);
38 +
39 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// fpga4student.com: FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Sign-Extension
5 +module sign_extend(sOut32,sIn16);
6 +output [31:0] sOut32;
7 +input [15:0] sIn16;
8 +assign sOut32 = {{16{sIn16[15]}},sIn16};
9 +endmodule
10 +// Shift left 2 module
11 +module shift_left_2(Out32, In32);
12 +output [31:0] Out32;
13 +input [31:0] In32;
14 +
15 +assign Out32 = {In32[29:0],2'b00};
16 +endmodule
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Sign-Extension
5 +module sign_extend(sOut32,sIn16);
6 +output [31:0] sOut32;
7 +input [15:0] sIn16;
8 +assign sOut32 = {{16{sIn16[15]}},sIn16};
9 +endmodule
10 +// Shift left 2 module
11 +module shift_left_2(Out32, In32);
12 +output [31:0] Out32;
13 +input [31:0] In32;
14 +
15 +assign Out32 = {In32[29:0],2'b00};
16 +endmodule
No preview for this file type
1 +onerror {resume}
2 +quietly WaveActivateNextPane {} 0
3 +add wave -noupdate -radix unsigned /WB_forward/ReadData1Out
4 +add wave -noupdate -radix unsigned /WB_forward/ReadData2Out
5 +add wave -noupdate -radix unsigned -expand /WB_forward/WriteRegister
6 +TreeUpdate [SetDefaultTree]
7 +WaveRestoreCursors {{Cursor 1} {14766920800 fs} 0}
8 +quietly wave cursor active 1
9 +configure wave -namecolwidth 150
10 +configure wave -valuecolwidth 100
11 +configure wave -justifyvalue left
12 +configure wave -signalnamewidth 0
13 +configure wave -snapdistance 10
14 +configure wave -datasetprefix 0
15 +configure wave -rowmargin 4
16 +configure wave -childrowmargin 2
17 +configure wave -gridoffset 0
18 +configure wave -gridperiod 1
19 +configure wave -griddelta 40
20 +configure wave -timeline 0
21 +configure wave -timelineunits fs
22 +update
23 +WaveRestoreZoom {15091825900 fs} {15930686700 fs}
This diff is collapsed. Click to expand it.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
1 +m255
2 +K4
3 +z0
4 +cModel Technology
1 +`timescale 1 ps / 100 fs
2 +// FPGA projects, Verilog Projects, VHDL projects
3 +// Verilog project: 32-bit 5-stage Pipelined MIPS Processor in Verilog
4 +// Zero-Extension
5 +module zero_extend(zOut32,zIn16);
6 +output [31:0] zOut32;
7 +input [15:0] zIn16;
8 +assign zOut32 = {{16{1'b0}},zIn16};
9 +endmodule