2020-12-12 06:59:14 +00:00
|
|
|
module mips_cpu_pc(
|
2020-12-16 13:21:57 +00:00
|
|
|
input logic clk,
|
|
|
|
input logic rst,
|
|
|
|
input logic[31:0] Instr,
|
|
|
|
input logic[31:0] JumpReg,
|
|
|
|
input logic[1:0] pc_ctrl,
|
|
|
|
output logic[31:0] pc_out,
|
|
|
|
output logic active
|
2020-12-02 17:23:28 +00:00
|
|
|
);
|
|
|
|
|
2020-12-16 13:21:57 +00:00
|
|
|
logic[31:0] out_cpc_out;
|
|
|
|
logic[31:0] out_npc_out;
|
|
|
|
logic[31:0] in_npc_in;
|
2020-12-02 17:23:28 +00:00
|
|
|
|
2020-12-16 13:21:57 +00:00
|
|
|
assign pc_out = out_cpc_out;
|
2020-12-16 12:29:22 +00:00
|
|
|
|
2020-12-16 13:21:57 +00:00
|
|
|
always @(*) begin
|
|
|
|
case(pc_ctrl)
|
|
|
|
2'd0: begin
|
|
|
|
in_npc_in = out_npc_out + 32'd4;//No branch or jump or load.
|
|
|
|
end
|
|
|
|
2'd1: begin
|
|
|
|
in_npc_in = out_npc_out + {{14{Instr[15]}}, Instr[15:0], 2'b00};
|
|
|
|
end
|
|
|
|
2'd2: begin
|
|
|
|
in_npc_in = {out_npc_out[31:28], Instr[25:0], 2'b00};
|
|
|
|
end
|
|
|
|
2'd3: begin
|
|
|
|
in_npc_in = JumpReg;
|
|
|
|
end
|
|
|
|
endcase
|
2020-12-12 06:59:14 +00:00
|
|
|
end
|
|
|
|
|
2020-12-16 13:21:57 +00:00
|
|
|
mips_cpu_cpc cpc(
|
|
|
|
//Inputs for cpc
|
|
|
|
.clk(clk),
|
|
|
|
.rst(rst),
|
|
|
|
.cpc_in(out_npc_out),
|
|
|
|
//Outputs for cpc
|
|
|
|
.cpc_out(out_cpc_out),
|
|
|
|
.active(active)
|
|
|
|
);
|
2020-12-15 15:53:30 +00:00
|
|
|
|
2020-12-16 13:21:57 +00:00
|
|
|
mips_cpu_npc npc(
|
|
|
|
//Inputs for npc
|
|
|
|
.clk(clk),
|
|
|
|
.rst(rst),
|
|
|
|
.npc_in(in_npc_in),
|
|
|
|
//Outputs for npc
|
|
|
|
.npc_out(out_npc_out)
|
|
|
|
);
|
2020-11-30 12:08:58 +00:00
|
|
|
|
2020-12-16 13:21:57 +00:00
|
|
|
endmodule
|