-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpc.v
More file actions
32 lines (29 loc) · 1021 Bytes
/
pc.v
File metadata and controls
32 lines (29 loc) · 1021 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
module pc(
input wire clk,
input wire rst_n,
input wire [1:0] MUX_output,
input wire [6:0] imm,
input wire [15:0] alu_out,
output reg [15:0] nxt_instr
);
// Duplicate the MSB 9 times, then concat with 7 bit immediate value
wire [15:0] sign_extend_imm;
assign sign_extend_imm = {{9{imm[6]}}, imm[6:0]};
always @(posedge clk or negedge rst_n) begin
// Reset PC when reset signal is given
if (!rst_n)
nxt_instr <= 16'h0000;
else begin
case (MUX_output)
// Increment PC as usual
2'b00: nxt_instr <= nxt_instr + 16'h0001;
// Increment PC then add imm value
2'b01: nxt_instr <= nxt_instr + 16'h0001 + sign_extend_imm;
// Jump to address indicated by out of ALU
2'b10: nxt_instr <= alu_out;
// Increment PC as usual
default: nxt_instr <= nxt_instr + 16'h0001;
endcase
end
end
endmodule