-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_tb.v
85 lines (72 loc) · 1.44 KB
/
cpu_tb.v
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
`timescale 1 ns/10 ps // time-unit = 1 ns, precision = 10 ps
`include "cpu.v"
module cpu_tb;
localparam period = 20;
wire [7:0] bus = 8'b00000000;
reg [7:0] _bus;
reg pr_mode;
reg [3:0] pr_address;
reg [7:0] pr_data;
reg instr_load;
reg address_send;
reg debug = 1;
reg clk;
reg rst = 0;
reg [3:0] opcode;
reg [3:0] flags;
// control signals
wire halt;
wire reg_a_in;
wire reg_a_out;
wire reg_b_in;
wire reg_b_out;
wire alu_out;
wire alu_sub;
wire instr_in;
wire instr_out;
wire mar_in;
wire ram_in;
wire ram_out;
wire reg_out;
wire pc_inc;
wire pc_out;
wire pc_jmp;
wire [3:0] reg_flags_in;
// debug
wire [3:0] step_out;
wire [3:0] _program [0:11];
integer _cnt = 0;
assign bus = instr_in ? 8'bzzzzzzzz : _bus;
cpu cpu_(
.clk(clk),
.rst(rst),
.pr_mode(pr_mode),
.pr_address(pr_address),
.pr_data(pr_data),
.instr_load(instr_load),
.address_send(address_send),
.debug(debug)
);
initial begin
clk = 1'b0;
forever #2 clk = ~clk;
end
initial begin
debug = 1'b1;
flags = 4'b0011;
end
initial begin
$dumpfile("cpu_tb.vcd");
$dumpvars(0, cpu_tb);
for(integer i = 0; i < 12; i = i + 1) begin
instr_load <= (i % 2 == 0); #1;
opcode = i; #1;
address_send <= !(i % 2 == 0); #1
_bus = i * 10; #20;
end
// opcode = 1;
// bus = 12; #20;
$display("Howdy");
$finish;
end
endmodule