Question
Write a behavior model for calculating the next PC for an instruction. It will use information from the processor control module and the ALU to
Write a behavior model for calculating the next PC for an instruction. It will use information from the processor control module and the ALU to determine the destination for the next PC.
Use the following module interface:
module NextPClogic(NextPC, CurrentPC, SignExtImm64, Branch, ALUZero, Uncondbranch); input [63:0] CurrentPC, SignExtImm64; input Branch, ALUZero, Uncondbranch; output [63:0] NextPC; /* write your code here */ endmodule
Where SignExtImm64 is the output of the sign extender. Branch is true if the current instruction is a conditional branch instruction, Uncondbranch is true if the current instruction is an Unconditional Branch (B), and ALUZero is the Zero output of the ALU. Any additions with a constant should have a delay of 1, general addition should have a delay of 2, and any multiplexers should have a delay of 1 (This includes statements inside if/else statements).
Write a test module to test your modules correct operation. In your test code, use the $display command to print the inputs (CurrentPC,SignExtImm64, Branch, ALUZero, Uncondbranch) and the output (NextPC).
Here is the testbench for the Verilog code to write
`timescale 1ns / 1ps
`define STRLEN 32
module NextPClogicTest;
task passTest;
input [63:0] actualOut, expectedOut;
input [`STRLEN*8:0] testType;
inout [7:0] passed;
if(actualOut == expectedOut) begin $display ("%s passed", testType); passed = passed + 1; end
else $display ("%s failed: %d should be %d", testType, actualOut, expectedOut);
endtask
task allPassed;
input [7:0] passed;
input [7:0] numTests;
if(passed == numTests) $display ("All tests passed");
else $display("Some tests failed");
endtask
// Inputs
reg [63:0] CurrentPC, SignExtImm64;
reg Branch, ALUZero, Uncondbranch;
reg [7:0] passed;
reg [7:0] numTests;
// Outputs
wire [63:0] NextPC;
reg[63:0] expectedNextPC;
// Instantiate the Unit Under Test (UUT)
NextPClogic uut(
.CurrentPC(CurrentPC),
.SignExtImm64(SignExtImm64),
.Branch(Branch),
.ALUZero(ALUZero),
.Uncondbranch(Uncondbranch),
.NextPC(NextPC));
initial begin
// Initialize Inputs
CurrentPC = 64'b0;
SignExtImm64 = 64'b0;
Branch = 1'b0;
ALUZero = 1'b0;
Uncondbranch = 1'b0;
passed = 7'b0;
numTests = 7'b0;
#3;
CurrentPC = 64'h10;
SignExtImm64 = 64'b0;
Branch = 1'b0;
ALUZero = 1'b0;
Uncondbranch = 1'b0;
expectedNextPC = 64'h14;
#4;
passTest(NextPC, expectedNextPC, "PC+4 Test", passed);
numTests = numTests + 1;
CurrentPC = 64'h10;
SignExtImm64 = 64'h2;
Branch = 1'b1;
ALUZero = 1'b1;
Uncondbranch = 1'b0;
expectedNextPC = 64'h18;
#4;
passTest(NextPC, expectedNextPC, "Conditional - Take Branch Test", passed);
numTests = numTests + 1;
CurrentPC = 64'h10;
SignExtImm64 = 64'h3;
Branch = 1'b1;
ALUZero = 1'b0;
Uncondbranch = 1'b0;
expectedNextPC = 64'h14;
#4;
passTest(NextPC, expectedNextPC, "Conditional - Don't Take Branch Test", passed);
numTests = numTests + 1;
CurrentPC = 64'h10;
SignExtImm64 = 64'h4;
Branch = 1'b0;
ALUZero = 1'b0;
Uncondbranch = 1'b1;
expectedNextPC = 64'h20;
#4;
passTest(NextPC, expectedNextPC, "Unconditional Branch Test", passed);
numTests = numTests + 1;
allPassed(passed, numTests);
$finish;
end
endmodule
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started