summaryrefslogtreecommitdiff
path: root/verilog/regfile.v
diff options
context:
space:
mode:
authorJoshua Yun <jjyun4@illinois.edu>2023-08-28 14:42:23 -0500
committerJoshua Yun <jjyun4@illinois.edu>2023-08-28 14:42:23 -0500
commitc1fa3c36da28e9e947f6279329c47777f31fe7a2 (patch)
treebd321c8e33200427b23bffe96c7c1bae90d8a044 /verilog/regfile.v
parentd069ea63cce08c0f5c8d7da7f8ab05115bd8d856 (diff)
downloadriscv-processor-inorder-master.tar.gz
Added new riscv processor design into git repoHEADmaster
Diffstat (limited to 'verilog/regfile.v')
-rw-r--r--verilog/regfile.v36
1 files changed, 36 insertions, 0 deletions
diff --git a/verilog/regfile.v b/verilog/regfile.v
new file mode 100644
index 0000000..56d107f
--- /dev/null
+++ b/verilog/regfile.v
@@ -0,0 +1,36 @@
+`default_nettype none
+`timescale 1ns/1ps
+
+module regfile (
+ input wire clk, we,
+ input wire [4:0] r1addr, r2addr, waddr,
+ input wire [31:0] wdata,
+ output wire [31:0] r1data, r2data
+);
+
+reg [31:0] registers [1:31];
+
+/* Async Read on second half of cycle */
+assign r1data = registers[r1addr];
+assign r2data = registers[r2addr];
+
+/* Async write at the beginning of the cycle */
+always @ (negedge clk) begin
+ if (we == 1'b1 && waddr != 5'b0) begin
+ registers[waddr] <= wdata;
+ end
+end
+
+// Debugging Access Functions
+`ifdef verilator
+ export "DPI-C" task get_reg_value;
+ task get_reg_value;
+ input bit [4:0] get_addr;
+ output bit [31:0] reg_val;
+ begin
+ reg_val = registers[get_addr];
+ end
+ endtask
+`endif
+
+endmodule