forked from skynatepro/MIPS32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramCounter.v
More file actions
42 lines (38 loc) · 1.26 KB
/
Copy pathProgramCounter.v
File metadata and controls
42 lines (38 loc) · 1.26 KB
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
`timescale 1ns / 1ps
module ProgramCounter(
input clk,
input reset,
input zero,
input branch,
input jump,
input [25:0] jumpAddress,
input [15:0] branchOffset,
input [31:0] regAddress,
output reg [31:0] pc
);
wire [31:0] pcPlus4;
reg [1:0] pcControl;
initial
begin
pc <= 32'h00000000;
end
assign pcPlus4 = pc + 1;
always @(posedge clk)
begin
if(reset == 1)
pc <= 32'h00000000;
else
begin
pcControl = ( branch & zero == 1)? 2'b10: 2'b00;
pcControl = (jump)?2'b11:pcControl;
case(pcControl)
2'b00: pc <= pcPlus4; //Increment of program counter by 4
2'b11: pc <= {pcPlus4[31:26],jumpAddress}; //Jump address calculation.
2'b01: pc <= regAddress; //Initial address
2'b10: pc <= pcPlus4 + {{14{branchOffset[15]}},branchOffset[15:0]}; //Branch address calculation.
default: pc<= pcPlus4;
endcase
end
$display("pc - %d clk -%d reset- %d pcControl- %b",pc,clk,reset,pcControl);
end
endmodule