-
Notifications
You must be signed in to change notification settings - Fork 1
/
program_counter.v
65 lines (56 loc) · 1.19 KB
/
program_counter.v
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 09/28/2017 12:53:39 AM
// Design Name:
// Module Name: program_counter
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module program_counter(
clk, //clock
rst,
pc,
pc_control,
jump_address,
branch_offset,
reg_address
);
input clk;
input rst;
input [2:0] pc_control;
input [25:0] jump_address;
input [15:0] branch_offset;
input [31:0] reg_address;
output reg [31:0] pc;
wire [31:0] pc_plus_4;
assign pc_plus_4 = pc + 4;
always @(posedge clk or posedge rst)
begin
if (rst)
begin
pc <= 32'd0;
end
else
begin
case (pc_control)
3'b000 : pc <= pc_plus_4;
3'b001 : pc <= {pc_plus_4[31:28], jump_address, 2'b00};
3'b010 : pc <= reg_address;
3'b011 : pc <= pc_plus_4 + { {14{branch_offset[15]}}, branch_offset[15:0], 2'b00 };
default: pc <= pc_plus_4;
endcase
end
end
endmodule