forked from Antimony5292/CPU-on-FPGA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregfile.v
More file actions
72 lines (69 loc) · 1.97 KB
/
Copy pathregfile.v
File metadata and controls
72 lines (69 loc) · 1.97 KB
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
69
70
71
72
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2019/10/20 10:32:16
// Design Name:
// Module Name: regfile
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
`include "define.v"
module regfile(
input wire clk,
input wire rst,
input wire [`RegAddrBus] waddr,
input wire [`RegBus] wdata,
input wire we,
input wire [`RegAddrBus] raddr1,
input wire re1,
input wire [`RegAddrBus] raddr2,
input wire re2,
output reg [`RegBus] rdata1,
output reg [`RegBus] rdata2
);
reg [`RegBus] regs[0:`RegNum-1];
always @ (posedge clk) begin
if (rst == `RstDisable) begin
if ((we == `WriteEnable) && (waddr != `RegNumLog2'h0)) begin
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
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
endmodule