-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_counter.v
More file actions
40 lines (36 loc) · 772 Bytes
/
program_counter.v
File metadata and controls
40 lines (36 loc) · 772 Bytes
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
`timescale 1ns / 1ps
module program_counter(
input clk,
input rst_n_i,
input [31:0] additinal,
input [31:0] jalr_add,
input jalr_o,
input en_add,
input en_pc,
output [31:0] pc
);
reg [31:0] currentPC = 0;
always @ (posedge clk or posedge rst_n_i)
begin
if (!rst_n_i)
begin
currentPC = 0;
end
else
if (en_pc == 1)
begin
if(jalr_o == 'b1)
begin
currentPC = jalr_add / 4;
end
else
begin
if(!en_add)
currentPC = pc + 1;
else
currentPC = pc + ($signed(additinal) / 4);
end
end
end
assign pc = currentPC;
endmodule