-
Notifications
You must be signed in to change notification settings - Fork 0
/
regfile.v
53 lines (41 loc) · 1.08 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
// Register File module
`include"define.v"
`timescale 1ns / 1ps
module regfile (
clk,
rst,
wen,
raddr1,
raddr2,
waddr,
wdata,
rdata1,
rdata2
);
input clk;
input rst;
input wen;
input [`ASIZE-1:0] raddr1;
input [`ASIZE-1:0] raddr2;
input [`ASIZE-1:0] waddr;
input [`DSIZE-1:0] wdata;
output [`DSIZE-1:0] rdata1;
output [`DSIZE-1:0] rdata2;
reg [`DSIZE-1:0] regdata [0:`NREG-1];
integer i;
always@(posedge clk)
begin
if(rst)
begin
for (i=0; i<`NREG; i=i+1)
regdata[i] <=0;
regdata[8] <=5;//hardcoding few values into register file for initialization
regdata[3] <=2;
end
else
regdata[waddr] <= (wen == 1) ? wdata : regdata[waddr];//when wen=1, then write wdata to LHS or mainintain the same data
end
assign rdata1 = ((wen) && (waddr == raddr1)) ? wdata : regdata[raddr1];//Here dataforwarding is done
//when both wen=1 and waddr=raddr1, then rdata1=wdata (this enables us to get the wdata in the same clock cycle-more useful in pipeling)
assign rdata2 = ((wen) && (waddr == raddr2)) ? wdata : regdata[raddr2];
endmodule