2020-12-12 06:59:14 +00:00
|
|
|
module mips_cpu_pc(
|
|
|
|
input logic clk,
|
|
|
|
input logic rst,
|
|
|
|
input logic[1:0] pc_ctrl,
|
|
|
|
input logic[31:0] instr,
|
|
|
|
input logic[31:0] reg_readdata,
|
|
|
|
output logic[31:0] pc_out,
|
|
|
|
output logic active
|
2020-12-02 17:23:28 +00:00
|
|
|
);
|
|
|
|
|
2020-12-12 06:59:14 +00:00
|
|
|
reg [31:0] pc_next, pc_lit_next;
|
2020-12-02 17:23:28 +00:00
|
|
|
|
|
|
|
initial begin
|
2020-12-15 11:16:01 +00:00
|
|
|
pc_out = 32'hBFC00000;
|
2020-12-12 06:59:14 +00:00
|
|
|
pc_next = pc_out + 32'd4;
|
|
|
|
end
|
|
|
|
|
|
|
|
assign pc_lit_next = pc_out + 32'd4;
|
2020-12-02 17:23:28 +00:00
|
|
|
|
2020-12-11 10:45:13 +00:00
|
|
|
always_ff @(posedge clk) begin
|
2020-12-02 17:23:28 +00:00
|
|
|
if (rst) begin
|
2020-12-11 10:45:13 +00:00
|
|
|
active <= 1;
|
|
|
|
pc_out <= 32'hBFC00000;
|
2020-12-12 06:59:14 +00:00
|
|
|
end else begin
|
2020-12-13 05:40:16 +00:00
|
|
|
if(pc_out == 32'd0) begin
|
|
|
|
active <= 0;
|
|
|
|
end
|
2020-12-12 06:59:14 +00:00
|
|
|
pc_out <= pc_next;
|
2020-12-11 10:45:13 +00:00
|
|
|
case(pc_ctrl)
|
2020-12-12 06:59:14 +00:00
|
|
|
default: begin
|
|
|
|
pc_next <= pc_out + 32'd4;
|
2020-12-11 10:45:13 +00:00
|
|
|
end
|
2020-12-12 06:59:14 +00:00
|
|
|
2'd1: begin // Branch
|
|
|
|
pc_next <= pc_out + 32'd4 + {{14{instr[15]}},instr[15:0],2'b00};
|
2020-12-11 10:45:13 +00:00
|
|
|
end
|
2020-12-12 06:59:14 +00:00
|
|
|
2'd2: begin // Jump
|
|
|
|
pc_next <= {pc_lit_next[31:28], instr[25:0], 2'b00};
|
2020-12-13 05:54:53 +00:00
|
|
|
$display("JUMPING");
|
2020-12-13 05:40:16 +00:00
|
|
|
$display("pc_lit_next: %h", pc_lit_next[31:28]);
|
|
|
|
$display("instr: %b", instr[25:0]);
|
|
|
|
$display("%h",pc_next);
|
2020-12-11 10:45:13 +00:00
|
|
|
end
|
2020-12-12 06:59:14 +00:00
|
|
|
2'd3: begin // Jump using Register
|
|
|
|
pc_next <= reg_readdata;
|
2020-12-11 10:45:13 +00:00
|
|
|
end
|
|
|
|
endcase
|
2020-12-12 06:59:14 +00:00
|
|
|
end
|
2020-12-02 17:23:28 +00:00
|
|
|
end
|
2020-11-30 12:08:58 +00:00
|
|
|
|
2020-12-07 21:46:01 +00:00
|
|
|
endmodule // pc
|