2022-08-14 23:05:44 +00:00
|
|
|
// Module Name: InstFetch
|
2022-08-13 23:36:00 +00:00
|
|
|
// Project Name: CSE141L
|
|
|
|
// Description: instruction fetch (pgm ctr) for processor
|
2022-08-12 05:01:28 +00:00
|
|
|
|
2022-08-13 23:36:00 +00:00
|
|
|
module InstFetch #(parameter T=10, parameter W=8)( // T is PC address size, W is the jump target pointer width, which is less
|
|
|
|
input logic Clk, Reset, // clock, reset
|
|
|
|
input logic BranchEZ, BranchNZ, BranchAlways, Zero, // branch control signals zero from alu signals; brnahc signals will be one hot encoding
|
2022-08-14 01:06:19 +00:00
|
|
|
input logic Done, // Done flag to indicate if the PC should increment at all
|
2022-08-13 23:36:00 +00:00
|
|
|
input logic [W-1:0] Target, // jump target pointer
|
2022-08-14 01:06:19 +00:00
|
|
|
output logic [T-1:0] ProgCtr,
|
2022-08-14 20:44:51 +00:00
|
|
|
output logic [T-1:0] ProgCtr_p1 // value of pc+1 for use in JAL instruction itself
|
2022-08-13 23:36:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
logic [T-1:0] PC;
|
|
|
|
|
|
|
|
always_ff @(posedge Clk) begin
|
|
|
|
if(Reset) PC <= 0; // if reset, set PC to 0
|
2022-08-14 20:44:51 +00:00
|
|
|
else if (BranchAlways) PC[W-1:0] <= Target; // if unconditional branch, assign PC to target
|
|
|
|
else if (BranchEZ && Zero) PC[W-1:0] <= Target; // if branch on zero and zero is true, then assign PC to target
|
|
|
|
else if (BranchNZ && !Zero) PC[W-1:0] <= Target; // if branch on non zero and zero is false, then assign PC to parget
|
2022-08-14 01:06:19 +00:00
|
|
|
else if (!Done) PC <= PC + 'b1; // if not a branch but CPU is not done, then
|
2022-08-13 23:36:00 +00:00
|
|
|
else PC <= PC;
|
|
|
|
end
|
|
|
|
|
2022-08-14 20:44:51 +00:00
|
|
|
assign ProgCtr = PC;
|
|
|
|
assign ProgCtr_p1 = ProgCtr + 1;
|
|
|
|
|
2022-08-13 23:36:00 +00:00
|
|
|
endmodule
|