@@ -7,8 +7,7 @@ module pc_tb;
7
7
reg clk;
8
8
reg rst_n;
9
9
reg [1 :0 ] MUX_output;
10
- reg [15 :0 ] pc_plus1;
11
- reg [15 :0 ] pc_plus1_imm;
10
+ reg [15 :0 ] imm;
12
11
reg [15 :0 ] alu_out;
13
12
14
13
// Output from the DUT
@@ -19,8 +18,7 @@ module pc_tb;
19
18
.clk(clk),
20
19
.rst_n(rst_n),
21
20
.MUX_output(MUX_output),
22
- .pc_plus1(pc_plus1),
23
- .pc_plus1_imm(pc_plus1_imm),
21
+ .imm(imm),
24
22
.alu_out(alu_out),
25
23
.nxt_instr(nxt_instr)
26
24
);
@@ -35,8 +33,7 @@ module pc_tb;
35
33
clk = 0 ;
36
34
rst_n = 1 ;
37
35
MUX_output = 2'b00 ;
38
- pc_plus1 = 16'h0000 ;
39
- pc_plus1_imm = 16'h0000 ;
36
+ imm = 16'h0000 ;
40
37
alu_out = 16'h0000 ;
41
38
#10 ; // Wait for a moment
42
39
@@ -57,7 +54,6 @@ module pc_tb;
57
54
// 3. Test Case: Sequential Increment (MUX_output = 00)
58
55
$display ("\n T=%0t: [TEST] Testing sequential increment (MUX_output = 2'b00)." , $time );
59
56
MUX_output = 2'b00 ;
60
- pc_plus1 = 16'h0001 ;
61
57
@(posedge clk);
62
58
#1 ;
63
59
if (nxt_instr === 16'h0001 ) begin
@@ -66,7 +62,6 @@ module pc_tb;
66
62
$display ("T=%0t: [FAIL] PC is 0x%h, expected 0x0001." , $time , nxt_instr);
67
63
end
68
64
69
- pc_plus1 = 16'h0002 ;
70
65
@(posedge clk);
71
66
#1 ;
72
67
if (nxt_instr === 16'h0002 ) begin
@@ -79,26 +74,24 @@ module pc_tb;
79
74
// 4. Test Case: Branch with Immediate (MUX_output = 01)
80
75
$display ("\n T=%0t: [TEST] Testing branch with immediate (MUX_output = 2'b01)." , $time );
81
76
MUX_output = 2'b01 ;
82
- pc_plus1_imm = 16'h1234 ;
77
+ imm = 16'h000E ; // Adds 14
83
78
// Set other inputs to different values to ensure they aren't selected
84
- pc_plus1 = 16'hFFFF ;
85
79
alu_out = 16'hEEEE ;
86
80
@(posedge clk);
87
81
#1 ;
88
- if (nxt_instr === 16'h1234 ) begin
82
+ if (nxt_instr === 16'h0011 ) begin
89
83
$display ("T=%0t: [PASS] PC branched to immediate address 0x%h." , $time , nxt_instr);
90
84
end else begin
91
- $display ("T=%0t: [FAIL] PC is 0x%h, expected 0x1234 ." , $time , nxt_instr);
85
+ $display ("T=%0t: [FAIL] PC is 0x%h, expected 0x0011 ." , $time , nxt_instr);
92
86
end
93
87
94
88
95
89
// 5. Test Case: Jump via ALU (MUX_output = 10)
96
90
$display ("\n T=%0t: [TEST] Testing jump via ALU output (MUX_output = 2'b10)." , $time );
97
91
MUX_output = 2'b10 ;
98
92
alu_out = 16'hABCD ;
99
- // Set other inputs to different values
100
- pc_plus1 = 16'hFFFF ;
101
- pc_plus1_imm = 16'hEEEE ;
93
+ // Set other input to different values
94
+ imm = 16'hEEEE ;
102
95
@(posedge clk);
103
96
#1 ;
104
97
if (nxt_instr === 16'hABCD ) begin
@@ -112,7 +105,6 @@ module pc_tb;
112
105
113
106
// a. Increment
114
107
MUX_output = 2'b00 ;
115
- pc_plus1 = 16'hABCE ;
116
108
@(posedge clk);
117
109
#1 ;
118
110
$display ("T=%0t: [INFO] Current PC: 0x%h (After increment)" , $time , nxt_instr);
@@ -126,12 +118,12 @@ module pc_tb;
126
118
127
119
// c. Branch
128
120
MUX_output = 2'b01 ;
129
- pc_plus1_imm = 16'hCAFE ;
121
+ imm = 16'h010F ;
130
122
@(posedge clk);
131
123
#1 ;
132
124
$display ("T=%0t: [INFO] Current PC: 0x%h (After branch)" , $time , nxt_instr);
133
- if (nxt_instr !== 16'hCAFE ) begin
134
- $display ("T=%0t: [FAIL] Back-to-back sequence failed. PC is 0x%h, expected 0xCAFE ." , $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);
135
127
end else begin
136
128
$display ("T=%0t: [PASS] Back-to-back sequence successful." , $time );
137
129
end
@@ -141,15 +133,14 @@ module pc_tb;
141
133
// of incrementing the PC
142
134
$display ("\n T=%0t: [TEST] Testing undefined MUX select (2'b11)." , $time );
143
135
MUX_output = 2'b11 ;
144
- pc_plus1 = 16'h0009 ; // Change inputs to see if they are ignored
145
- pc_plus1_imm = 16'h000A ;
146
- alu_out = 16'h000B ;
136
+ imm = 16'h148A ; // Random Inputs to ensure they're ignored
137
+ alu_out = 16'h000B ;// Random Inputs to ensure they're ignored
147
138
@(posedge clk);
148
139
#1 ;
149
- if (nxt_instr === 16'h0009 ) begin
150
- $display ("T=%0t: [PASS] PC correctly incremented to PC+1 at 16'h0009 ." , $time , nxt_instr);
140
+ if (nxt_instr === 16'hC000 ) begin
141
+ $display ("T=%0t: [PASS] PC correctly incremented to PC+1 at 0x%h ." , $time , nxt_instr);
151
142
end else begin
152
- $display ("T=%0t: [FAIL] PC changed to 16'h000A or 16'h000B , expected it to go to 16'h0009 ." , $time , nxt_instr);
143
+ $display ("T=%0t: [FAIL] PC changed to 0x%h , expected it to go to 16'hC000 ." , $time , nxt_instr);
153
144
end
154
145
155
146
// 8. Test Case: Asynchronous Reset again
0 commit comments