-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreg_file.v
More file actions
48 lines (44 loc) · 764 Bytes
/
reg_file.v
File metadata and controls
48 lines (44 loc) · 764 Bytes
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
`timescale 10 ns / 1 ns
`define DATA_WIDTH 32
`define ADDR_WIDTH 5
`define REG_NUM 32
module reg_file(
input clk,
input resetn,
input [`ADDR_WIDTH - 1:0] waddr,
input [`ADDR_WIDTH - 1:0] raddr1,
input [`ADDR_WIDTH - 1:0] raddr2,
input wen,
input [`DATA_WIDTH - 1:0] wdata,
output [`DATA_WIDTH - 1:0] rdata1,
output [`DATA_WIDTH - 1:0] rdata2
);
//Definition
reg [`DATA_WIDTH-1:0] mem [`REG_NUM-1:0];
//Input
always @(posedge clk)
begin
if(resetn==0)
begin
mem [0]<=0;
if(wen==1 && waddr!=0)
begin
mem[waddr]<=wdata;
end
else
;
end
else
begin
if(wen==1 && waddr!=0)
begin
mem[waddr]<=wdata;
end
else
;
end
end
//Output
assign rdata1 = mem[raddr1];
assign rdata2 = mem[raddr2];
endmodule