25 lines
563 B
Systemverilog
25 lines
563 B
Systemverilog
`ifndef INSTRUCTION_COUNTER_H
|
|
`define INSTRUCTION_COUNTER_H
|
|
|
|
module instruction_counter #(parameter width=5)(
|
|
input logic [0:0] clk, input logic [0:0] rst, 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 or posedge rst) begin
|
|
if (rst) begin
|
|
pc <= {(2**width){1'b0}};
|
|
end else if (we) begin
|
|
pc <= W;
|
|
end else begin
|
|
pc <= pc + 4;
|
|
end
|
|
end
|
|
|
|
assign addr = pc;
|
|
endmodule
|
|
`endif
|