-
Notifications
You must be signed in to change notification settings - Fork 0
/
Single_cycle_processor_tb.v
185 lines (150 loc) · 4.65 KB
/
Single_cycle_processor_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//`include "processor.v"
module processor_tb();
reg clk,reset,freeze_pc;
//wires for fetch stage
wire [31:0]pc_out_from_pc;
wire [15:0]instr_from_mux;
wire [15:0] immediate;
/////////////
///////////////////////
//first buffer outputs
wire[31:0] pc_out_from_buff1;
wire [15:0] instr_out_from_buff1;
////////////////////////
/////////////////////
//wires for decode stage
//inputs
wire register_write_in;
wire [2:0]write_addr;
wire [15:0] write_data;
//outputs
wire [2:0]alu_op,jump_type;
wire register_write_out, alu_src, mem_write, mem_to_register, mem_read, branch,in_port,stack_or_data,pc_to_stack,inc_dec_sp,imm,ldd_or_std;
wire [15:0] read_data_1, read_data_2;
///////////////
//////////////
//buff2 outputs
wire [2:0] alu_op_buff2,jump_type_buff2,read_addr_1_buff2,read_addr_2_buff2;
wire register_write_buff2,alu_src_buff2,mem_write_buff2,mem_to_register_buff2,mem_read_buff2;
wire branch_buff2,in_port_buff2,stack_or_data_buff2,pc_to_stack_buff2,inc_dec_sp_buff2;
wire imm_buff2,ldd_or_std_buff2;
wire [15:0] immediate_buff2,read_data_1_buff2,read_data_2_buff2;
///////////////
//////////////
//wires for execute stage
wire [15:0] alu_out;
wire [2:0] flags_out;
/////////////
//////////////
//buff3 outputs
wire [2:0]jump_type_buff3,read_addr_buff3;
wire register_write_buff3,mem_write_buff3,mem_to_register_buff3,mem_read_buff3;
wire branch_buff3,in_port_buff3,stack_or_data_buff3,pc_to_stack_buff3,inc_dec_sp_buff3;
wire ldd_or_std_buff3;
wire [15:0] read_data_2_buff3,alu_out_buff3;
///////////////
//memory stage wires
wire [15:0] data_out_from_mem;
////
////////////
//buff4 outputs
wire [15:0] alu_out_buff4,data_out_buff4;
wire register_write_buff4,mem_to_register_buff4;
wire [2:0] write_addr_buff4;
////////////////////////////
//wb stage wires
wire [15:0] data_out_from_wb;
//
// fetch stage
instruction_fetch_stage fetch(clk,reset,freeze_pc,imm,pc_out_from_pc,instr_from_mux,immediate);
buffer buff1(1'b1,pc_out_from_pc,instr_from_mux,clk,reset,pc_out_from_buff1,instr_out_from_buff1);
/////
//decode stage
decode_stage dec(instr_out_from_buff1,
register_write_buff4,write_addr_buff4,alu_op,
register_write_out,alu_src,mem_write,
mem_to_register,mem_read,branch,jump_type,
in_port,stack_or_data,pc_to_stack,inc_dec_sp,
imm,ldd_or_std, data_out_from_wb, read_data_1, read_data_2, clk, reset);
ID_IE_buffer buff2(instr_out_from_buff1[12:10] ,instr_out_from_buff1[9:7],
read_addr_1_buff2,read_addr_2_buff2,alu_op,register_write_out,alu_src,mem_write,mem_to_register,mem_read,
branch,jump_type,in_port,stack_or_data,pc_to_stack,inc_dec_sp,imm,ldd_or_std,read_data_1,read_data_2,
alu_op_buff2,register_write_buff2,alu_src_buff2,mem_write_buff2,mem_to_register_buff2,
mem_read_buff2,branch_buff2,jump_type_buff2,in_port_buff2,stack_or_data_buff2,
pc_to_stack_buff2,inc_dec_sp_buff2,imm_buff2,ldd_or_std_buff2,read_data_1_buff2,read_data_2_buff2,
immediate,immediate_buff2,
clk
);
/////
//execute stage
execute_stage exe1(imm_buff2,alu_op_buff2,clk,immediate_buff2,read_data_1_buff2,read_data_2_buff2
,reset,alu_out,flags_out
);
IE_MEM_buffer buff3(register_write_buff2,mem_write_buff2,
mem_to_register_buff2,mem_read_buff2,branch_buff2,jump_type_buff2,in_port_buff2,
stack_or_data_buff2,pc_to_stack_buff2,inc_dec_sp_buff2,ldd_or_std_buff2,read_data_2_buff2,
register_write_buff3,mem_write_buff3,mem_to_register_buff3,mem_read_buff3,
branch_buff3,jump_type_buff3,in_port_buff3,stack_or_data_buff3,pc_to_stack_buff3,
inc_dec_sp_buff3,ldd_or_std_buff3,read_data_2_buff3,alu_out,alu_out_buff3,
read_addr_1_buff2,read_addr_buff3
,clk
);
//////////////
//memory stage
memory_stage memo1(mem_read_buff3,mem_write_buff3,alu_out_buff3,data_out_from_mem,read_addr_buff3,read_addr_buff3,clk);
MEM_WB_buffer buff4(alu_out_buff3,data_out_buff4,
register_write_buff3,mem_to_register_buff3,in_port_buff3
,read_addr_buff3,register_write_buff4,mem_to_register_buff4,in_port_buff4,write_addr_buff4,
alu_out_buff4,data_out_buff4,clk
);
////////////
///wb stage
write_back_stage wb(data_out_buff4,alu_out_buff4,mem_to_register_buff4,data_out_from_wb);
////
always
#50 clk=~clk;
initial begin
clk = 1;
reset = 1;
freeze_pc = 1;
#100
reset = 0;
freeze_pc = 0;
#200
freeze_pc=1;
#300
freeze_pc = 0;
#200
freeze_pc=1;
#300;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
#400;
freeze_pc = 0;
#100
freeze_pc=1;
#400;
end
endmodule