EE471 Group#11 Lab#1
EE471 Group#11 Lab#1
EE471 Group#11 Lab#1
Group 11
2. Lab Objectives:
For this lab1 you are to construct a 32 by 32 register file using Verilog HDL. The register file is
introduced in chapter 4 of the class textbook. Within the 32 by 32 register file is an array of 32 different
32-bit registers. These registers must be constructed from D flip-flops (positive edge-triggered). Note
that for MIPS, register zero ($zero) is hardwired to always output the value zero, regardless of what may
or may not be written to it. The figure below shows a block diagram of a register file (this is a modified
reproduction of figure 4.7 on page 310 of the textbook: Computer Organization and Design 4th edition by
Patterson and Hennessy).
5
32
5
5
32
Read Register 1 and Read Register 2 select the registers whose values are output on
the Read Data 1 bus and Read Data 2 bus respectively. The Write Register input bus selects the
target of the write; when RegWrite is true, the information on the Write Data bus register is
written into that register.
Computer resources and software tools:
PCs with Software Quartus II, ModelSim, IVerilog installed, testbench file: regstim.v
Implementation:
A simple implementation of the 32 by 32 MIPS register file can be made using
Registers composed of D flip-flops, a 5:32 enabled decoder, and two large to 32 multiplexors
32
Register 1
32
Register 2
32
32
RegWri
te
Register 31
Write Register 5
Read
Data 1
32
5
1
Read Register
3
2
32
Write Data
32
32
32
Read
Data 2
32
5
2
Each 32-bit register is simply an array of 32 D flip-flops:
Read Register
Data In
Register
Register
Enable
32
Data Out
3. Design:
a. Decoder:
We use decoder 3to8 and 2to4 to make decoder 5to32
b. Multiplexer:
First, we make the multiplexer 2to1.
c. Regfile:
First we make a 1 bit register by using D flipflop
Enable
D
clock
Register Cell
clear
4. Code :
a. Decoder :
Decoder 2 to 4 :
module decoder2to4(in1, in2, y0, y1, y2, y3, RegWrite);
input RegWrite;
input in1, in2;
output y0, y1, y2, y3;
Decoder 3 to 8 :
module decoder3to8(w0, w1, w2, En, y1, y2, y3, y4, y5, y6, y7, y8);
input w0, w1, w2, En;
output y1, y2, y3, y4, y5, y6, y7, y8;
not not100(w2n, w2);
and and381(En1, w2n, En);
and and382(En2, w2, En);
Decoder 5 to 32 :
endmodule
b. Multiplexer :
Multiplexer 2 to 1
module mux2to1(data, w, y0, y1);
output data;
input w, y0, y1;
not n1(nw,w);
and a1(a,nw,y0);
and a2(b,w,y1);
or o1(data,a,b);
endmodule
Multiplexer 4 to 1
mux2to1 m0(data0,w0,y0,y1);
mux2to1 m1(data1,w0,y2,y3);
mux2to1 m2(data,w1,data1,data2)
endmodule
Multiplexer 16 to 1
module mux16to1(data, w3, w2, w1, w0, y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12,
y13, y14, y15);
output data;
input w3, w2, w1, w0, y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14,
y15;
endmodule
Multiplexer 32 to 1
module mux32to1(data, w4, w3, w2, w1, w0, y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11,
y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22, y23, y24, y25, y26, y27, y28, y29, y30,
y31);
output data;
input w4, w3, w2, w1, w0, y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13,
y14, y15,y16, y17, y18, y19, y20, y21, y22, y23, y24, y25, y26, y27, y28, y29, y30, y31;
mux16to1 m0(data0, w3, w2, w1, w0, y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12,
y13, y14, y15);
mux16to1 m1(data1, w3, w2, w1, w0, y16, y17, y18, y19, y20, y21, y22, y23, y24, y25, y26,
y27, y28, y29, y30, y31);
mux2to1 m3(data, w4, data0,data1);
endmodule
Multiplexer 32 to 32
module multiplexer(
input [4:0] ReadReg,
input [31:0] reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg10, reg11,
reg12, reg13, reg14, reg15, reg16, reg17,reg18, reg19, reg20, reg21, reg22, reg23, reg24,
reg25, reg26, reg27, reg28, reg29, reg30, reg31,
output [31:0] RegReadData
);
genvar i;
generate
for(i=0;i<32;i=i+1)
begin: muxblock
mux32to1 mux32to1(RegReadData[i], ReadReg[4], ReadReg[3], ReadReg[2],
ReadReg[1], ReadReg[0], reg0[i], reg1[i], reg2[i], reg3[i], reg4[i],reg5[i], reg6[i], reg7[i],
reg8[i], reg9[i], reg10[i], reg11[i], reg12[i], reg13[i], reg14[i], reg15[i],reg16[i], reg17[i],
reg18[i], reg19[i],reg20[i], reg21[i], reg22[i], reg23[i], reg24[i], reg25[i], reg26[i], reg27[i],
reg28[i], reg29[i], reg30[i], reg31[i]);
end
endgenerate
endmodule
c. Register
D flip flop
module DFlipFlop(q, qBar, D, clk, rst);
input D, clk, rst;
output q, qBar;
reg q;
not n1 (qBar, q);
always@ (negedge rst or posedge clk)
begin
if(rst)
q = 0;
else
q = D;
end
endmodule
1 bit register
not (not1,enable);
and (and1, data, enable);
and (and2, not1, Q);
or (or1, and1, and2);
DFlipFlop DFlipFlop(Q,or1,clk,rst);
assign out=Q;
endmodule
32 bit register
genvar i;
generate
for(i=0;i<32;i=i+1)
begin: block32bit
OnebitRegister onebit(clk,rst,enable,in[i],out[i]);
end
endgenerate
endmodule
32 x 32 bit register
module register32x32(
input clk, rst,
input [31:0] enable,
input [31:0] WriteData,
output [31:0] reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg10, reg11, reg12,
reg13, reg14,reg15, reg16, reg17, reg18, reg19, reg20, reg21, reg22, reg23, reg24, reg25,
reg26, reg27, reg28, reg29, reg30, reg31);
endmodule
d. Regfile
Module regfile(readData1,readData2,WriteData,ReadReg1,
ReadReg2,WriteReg,RegWrite,clk);
input clk, RegWrite;
input [4:0] ReadReg1, ReadReg2, WriteReg;
input [31:0] WriteData;
output [31:0] readData1, readData2;
wire [31:0] reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8, reg9, reg10, reg11, reg12,
reg13, reg14, reg15, reg16, reg17,reg18, reg19, reg20, reg21, reg22, reg23, reg24, reg25,
reg26, reg27, reg28, reg29, reg30, reg31;
wire [31:0] enable;
reg rst=0;
register32x32 register(clk,rst,enable, WriteData, reg0, reg1, reg2, reg3, reg4, reg5, reg6,
reg7, reg8, reg9, reg10, reg11, reg12, reg13, reg14, reg15, reg16, reg17,reg18, reg19,
reg20, reg21, reg22, reg23, reg24, reg25, reg26, reg27, reg28, reg29, reg30, reg31);
multiplexer multiplexer1(ReadReg1, reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8,
reg9, reg10, reg11, reg12, reg13, reg14, reg15, reg16, reg17,reg18, reg19, reg20, reg21,
reg22, reg23, reg24, reg25, reg26, reg27, reg28, reg29, reg30, reg31, readData1);
multiplexer multiplexer2(ReadReg2, reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7, reg8,
reg9, reg10, reg11, reg12, reg13, reg14, reg15, reg16, reg17,reg18, reg19, reg20, reg21,
reg22, reg23, reg24, reg25, reg26, reg27, reg28, reg29, reg30, reg31, readData2);
endmodule
5. Simulation
a. Decoder:
In this case we make a test bench to check the work of module decoder
The decoder work with enable is active
c. Register32x32:
In this case, we simulate the case that we write data from 0-31 to 32 register with
clock and reset is not active.