-
Notifications
You must be signed in to change notification settings - Fork 1
/
regfile.v
68 lines (62 loc) · 1.77 KB
/
regfile.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
`include "defines.v"
module regfile(input wire clk,
input wire rst,
//input [4:0]reg_p,
input wire we,
input wire [`RegAddrBus] waddr,
input wire [`RegBus] wdata,
input wire re1,
input wire [`RegAddrBus] raddr1,
output reg [`RegBus] rdata1,
input wire re2,
input wire [`RegAddrBus] raddr2,
output reg [`RegBus] rdata2
//output reg [`RegBus]reg_data
);
reg [`RegBus] regs [0:`RegNum-1];
always @(posedge clk) begin
/*дָ???*/
if (rst == `RstDisable) begin
if ((we == `WriteEnable) && (waddr != `RegNumLog2'h0)) begin
/*дʹ�ܣ����ҵ�ַ��Ϊ0*/
regs[waddr] <= wdata;
end
end
end
always @(*) begin
if (rst == `RstEnable) begin
rdata1 <= `ZeroWord;
end
else if (raddr1 == `RegNumLog2'h0) begin
rdata1 <= `ZeroWord;
end
else if ((raddr1 == waddr) && (we == `WriteEnable) && (re1 == `ReadEnable)) begin
/*��дͬһ��ַ��ֱ�Ӷ�???*/
rdata1 <= wdata;
end
else if (re1 == `ReadEnable) begin
/*��ָ???*/
rdata1 <= regs[raddr1];
end
else begin
rdata1 <= `ZeroWord;
end
end
always @(*) begin
if (rst == `RstEnable) begin
rdata2 <= `ZeroWord;
end
else if (raddr2 == `RegNumLog2'h0) begin
rdata2 <= `ZeroWord;
end
else if ((raddr2 == waddr) && (we == `WriteEnable) && (re2 == `ReadEnable)) begin
rdata2 <= wdata;
end
else if (re2 == `ReadEnable) begin
rdata2 <= regs[raddr2];
end
else begin
rdata2 <= `ZeroWord;
end
end
endmodule