-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregfile32x32.v
49 lines (44 loc) · 1002 Bytes
/
regfile32x32.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Edittor: N.D LINH.
// Last edit: 31/10/2019.
//------------------------
module regfile
(input clk,
input reset,
input write,
input [4:0] wrAddrD,
input [4:0] rdAddrA,
input [4:0] rdAddrB,
input [31:0] wrDataD,
output [31:0] rdDataA,
output [31:0] rdDataB);
/* Dung decoder module thay vi decode truc tiep trong reg file
wire [4:0] wrAddrD, rdAddrA, rdAddrB;
// Instruction decode
assign wrAddrD = instr[11:7];
assign rdAddrA = instr[19:15];
assign wrAddrB = instr[24:20]; */
reg [31:0] regfile [0:31];
integer j;
initial begin
for (j = 0; j < 32; j = j + 1) begin
regfile[j] <= 0;
end
end
assign rdDataA = regfile[rdAddrA];
assign rdDataB = regfile[rdAddrB];
integer i;
always @(negedge clk) begin
if (reset) begin
for (i = 0; i < 32; i = i + 1) begin
regfile[i] <= 0;
end
end else begin
if (write) begin
if (wrAddrD != 0)
regfile[wrAddrD] <= wrDataD;
end
end // else: !if(reset)
// x0 always is zero;
regfile[0] <= 0;
end
endmodule