-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcModule.v
More file actions
57 lines (47 loc) · 1.32 KB
/
Copy pathpcModule.v
File metadata and controls
57 lines (47 loc) · 1.32 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
`include "constants.v"
// 0: Pc = Pc + 1
// 1: PC = {PC[31:26], Immediate26 }
// 2: PC = PC + sign_extended (Imm16)
// 3: PC = top of the stack
module pcModule(clock, PC, PCsrc, immediate26, Imm16, topStack, EN);
input wire clock;
input wire [1:0] PCsrc;
input wire [25:0] immediate26;
input wire [31:0] topStack;
input wire signed [15:0] Imm16;
input wire EN;
// PC Output
output reg [31:0] PC;
// To store assignments
wire [31:0] PC1;
wire [31:0] Immediate;
// PC + 1
assign PC1 = PC + 32'd1;
// Concatinate PC and immediate
assign Immediate = {PC[31:26], immediate26};
initial begin
PC <= 32'd0;
end
always @(posedge clock) begin
if(EN) begin
case (PCsrc)
pcDefault: begin
// PC = PC + 1
PC = PC1;
end
pcImm: begin
// PC = {PC[31:26], Immediate26 }
PC = Immediate;
end
pcSgnImm: begin
// PC = PC + sign_extended (Imm16)
PC = PC + {{16{Imm16[15]}}, Imm16};
end
pcStack: begin
// PC = top of the stack
PC = topStack;
end
endcase
end
end
endmodule