summaryrefslogtreecommitdiff
path: root/verilog/regfile.v
blob: 56d107fdf7c28ab36bb924127b986da6e5a6d976 (plain) (blame)
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
`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