Added instruction counter and register file

This commit is contained in:
riley committed 2026-10-08 14:13:38 +11:00
1 parent 5cb48095ce
commit 0ef2aeeb48
2 files changed
+43

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
`ifndef INSTRUCTION_COUNTER_H
`define INSTRUCTION_COUNTER_H
module instruction_counter #(parameter width=5)(
input logic [0:0] clk, input logic [0:0] we,
input logic [2**width-1:0] W,
output logic [2**width-1:0] addr
);
logic [2**width-1:0] pc;
always_ff (@posedge clk) begin
if (we) begin
pc <= W
else
pc <= pc + 4;
end
end
assign addr = pc;
endmodule
`endif
+22
View File
@@ -0,0 +1,22 @@
`ifndef REGISTER_FILE_H
`define REGISTER_FILE_H
module register_file #(parameter width=5, parameter nregs=16)(
input logic [0:0] clk, input logic[0:0] we,
input logic [$clog(nregs)-1:0] A_W1, input logic [2**width-1:0] W1,
input logic [$clog(nregs)-1:0] A_R1, output logic [2**width-1:0] R1,
input logic [$clog(nregs)-1:0] A_R2, output logic [2**width-1:0] R2
);
localparam BW = 2**width;
logic [2**width-1:0] regs[nregs];
always_ff @(posedge clk) begin
if (we & (A_W1 != {(2**width){1'b0}} )) begin
regs[A_W1] <= W1;
end
end
assign R1 = regs[A_R1];
assign R2 = regs[A_R2];
endmodule
`endif