This repository has been archived on 2023-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
cse141L-project/RTL/InstFetch.sv

28 lines
1.2 KiB
Systemverilog
Raw Normal View History

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,
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
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
assign ProgCtr = PC;
assign ProgCtr_p1 = ProgCtr + 1;
2022-08-13 23:36:00 +00:00
endmodule