-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_counter_tb.v
More file actions
65 lines (53 loc) · 1.21 KB
/
program_counter_tb.v
File metadata and controls
65 lines (53 loc) · 1.21 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Standalone testbench to verify key components
module pc_verify_tb;
reg clk, rst, inc, branch_en, halt;
reg [10:0] branch_addr;
wire [10:0] current_addr;
// Instantiate just the program counter
program_counter pc_test(
.clk(clk),
.rst(rst),
.inc(inc),
.branch_en(branch_en),
.halt(halt),
.branch_addr(branch_addr),
.current_addr(current_addr)
);
// Clock generation
initial begin
clk = 0;
forever #5 clk = ~clk;
end
// Test sequence
initial begin
// Initialize all inputs
rst = 1;
inc = 0;
branch_en = 0;
halt = 0;
branch_addr = 11'h100;
// Release reset after 2 cycles
repeat(2) @(posedge clk);
rst = 0;
// Test increment
repeat(2) @(posedge clk);
inc = 1;
$display("Testing increment");
repeat(3) @(posedge clk);
// Test branch
inc = 0;
branch_en = 1;
$display("Testing branch");
repeat(2) @(posedge clk);
// Test halt
branch_en = 0;
halt = 1;
$display("Testing halt");
repeat(2) @(posedge clk);
$finish;
end
// Monitor PC value
always @(posedge clk) begin
$display("PC Value: %d", current_addr);
end
endmodule