File size: 1,207 Bytes
78c261f | 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 33 34 35 36 37 38 39 | module pc_control(input [1:0]instr_type,input [4:0] opcode, input zero_signal, stop_bit, output reg [1:0] pc_src);
// pc_src logic
/*
always @(*)begin
if (instr_type == 2'b01 && zero_signal && opcode == 5'b00100) begin // I-type
pc_src = 2'b01; // branch taken
end
else if(instr_type == 2'b10) begin // J-type
pc_src = 2'b10; // jump
end
else if(stop_bit) begin // stop
pc_src = 2'b11; // Return Address
end
else if(instr_type == 2'b00 || instr_type == 2'b11) begin // R-type
pc_src = 2'b00; // pc + 4
end
else begin // default
pc_src = 2'b00; // pc + 4
end
end*/
// another simple implementation
wire branch;
wire jump;
assign branch = (instr_type == 2'b01 && zero_signal && opcode == 5'b00100) || stop_bit;
assign jump = (instr_type == 2'b10) || stop_bit;
// MUX to choose the pc_src value
always @* begin
case ({jump, branch})
2'b00: pc_src = 2'b00; // pc + 4
2'b01: pc_src = 2'b01; // branch taken
2'b10: pc_src = 2'b10; // jump
2'b11: pc_src = 2'b11; // Return Address
endcase
end
endmodule |