@@ -7,7 +7,7 @@ module pc_tb;
77 reg clk;
88 reg rst_n;
99 reg [1 :0 ] MUX_output;
10- reg [15 :0 ] imm;
10+ reg [6 :0 ] imm; // Input is in 2's compliment, so MSB is the sign bit
1111 reg [15 :0 ] alu_out;
1212
1313 // Output from the DUT
@@ -33,7 +33,7 @@ module pc_tb;
3333 clk = 0 ;
3434 rst_n = 1 ;
3535 MUX_output = 2'b00 ;
36- imm = 16'h0000 ;
36+ imm = 7'b0 ;
3737 alu_out = 16'h0000 ;
3838 #10 ; // Wait for a moment
3939
@@ -74,7 +74,7 @@ module pc_tb;
7474 // 4. Test Case: Branch with Immediate (MUX_output = 01)
7575 $display ("\n T=%0t: [TEST] Testing branch with immediate (MUX_output = 2'b01)." , $time );
7676 MUX_output = 2'b01 ;
77- imm = 16'h000E ; // Adds 14
77+ imm = 7'b0001110 ; // Adds 14
7878 // Set other inputs to different values to ensure they aren't selected
7979 alu_out = 16'hEEEE ;
8080 @(posedge clk);
@@ -91,7 +91,7 @@ module pc_tb;
9191 MUX_output = 2'b10 ;
9292 alu_out = 16'hABCD ;
9393 // Set other input to different values
94- imm = 16'hEEEE ;
94+ imm = 7'b1111110 ;
9595 @(posedge clk);
9696 #1 ;
9797 if (nxt_instr === 16'hABCD ) begin
@@ -118,12 +118,12 @@ module pc_tb;
118118
119119 // c. Branch
120120 MUX_output = 2'b01 ;
121- imm = 16'h010F ;
121+ imm = 7'b0100110 ; // imm = 38. Jumps to BF15 + 1 = BF16
122122 @(posedge clk);
123123 #1 ;
124124 $display ("T=%0t: [INFO] Current PC: 0x%h (After branch)" , $time , nxt_instr);
125- if (nxt_instr !== 16'hBFFF ) begin
126- $display ("T=%0t: [FAIL] Back-to-back sequence failed. PC is 0x%h, expected 0xBFFF ." , $time , nxt_instr);
125+ if (nxt_instr !== 16'hBF16 ) begin
126+ $display ("T=%0t: [FAIL] Back-to-back sequence failed. PC is 0x%h, expected 0xBF16 ." , $time , nxt_instr);
127127 end else begin
128128 $display ("T=%0t: [PASS] Back-to-back sequence successful." , $time );
129129 end
@@ -133,14 +133,14 @@ module pc_tb;
133133 // of incrementing the PC
134134 $display ("\n T=%0t: [TEST] Testing undefined MUX select (2'b11)." , $time );
135135 MUX_output = 2'b11 ;
136- imm = 16'h148A ; // Random Inputs to ensure they're ignored
136+ imm = 7'b1010101 ; // Random Inputs to ensure they're ignored
137137 alu_out = 16'h000B ;// Random Inputs to ensure they're ignored
138138 @(posedge clk);
139139 #1 ;
140- if (nxt_instr === 16'hC000 ) begin
140+ if (nxt_instr === 16'hBF17 ) begin
141141 $display ("T=%0t: [PASS] PC correctly incremented to PC+1 at 0x%h." , $time , nxt_instr);
142142 end else begin
143- $display ("T=%0t: [FAIL] PC changed to 0x%h, expected it to go to 16'hC000 ." , $time , nxt_instr);
143+ $display ("T=%0t: [FAIL] PC changed to 0x%h, expected it to go to 16'hBF17 ." , $time , nxt_instr);
144144 end
145145
146146 // 8. Test Case: Asynchronous Reset again
0 commit comments