1313
1414module cpu_pipelined (
1515 input clk,
16- input reset
16+ input reset,
17+ output end_program
1718);
1819 // program counter wale baba
1920 wire [63 :0 ] pc_next;
@@ -35,17 +36,21 @@ module cpu_pipelined(
3536 .pc(pc_current), // current PC se
3637 .instruction(instruction) // instruction nikalo
3738 );
39+
40+ wire nop_instruction;
41+ assign nop_instruction = instruction == 0 ; // no operation instruction
3842
3943 // IF/ID Pipeline Register
4044 wire [63 :0 ] if_id_pc;
4145 wire [31 :0 ] if_id_instruction;
46+ wire if_id_end_instruction, if_id_nop_instruction;
4247
4348 if_id_register if_id (
4449 .clk(clk),
4550 .reset(reset),
4651 .en(1'b1 ),
47- .d({pc_current, instruction}),
48- .q({ if_id_pc , if_id_instruction})
52+ .d({pc_current, instruction , nop_instruction }),
53+ .q({if_id_pc , if_id_instruction, if_id_nop_instruction })
4954 );
5055
5156 // control signals - CPU ko batate hai kya karna hai
@@ -94,14 +99,14 @@ module cpu_pipelined(
9499 // ID/EX Pipeline Register
95100 wire [63 :0 ] id_ex_pc, id_ex_reg_read_data1, id_ex_reg_read_data2;
96101 wire [31 :0 ] id_ex_instruction;
97- wire id_ex_branch, id_ex_mem_read, id_ex_mem_write, id_ex_mem_to_reg, id_ex_reg_write, id_ex_alu_src;
102+ wire id_ex_branch, id_ex_mem_read, id_ex_mem_write, id_ex_mem_to_reg, id_ex_reg_write, id_ex_alu_src, id_ex_nop_instruction ;
98103
99104 id_ex_register id_ex (
100105 .clk(clk),
101106 .reset(reset),
102107 .en(1'b1 ),
103- .d({if_id_pc, reg_read_data1, reg_read_data2, if_id_instruction, branch, mem_read, mem_write, mem_to_reg, reg_write, alu_src}),
104- .q({id_ex_pc, id_ex_reg_read_data1, id_ex_reg_read_data2, id_ex_instruction, id_ex_branch, id_ex_mem_read, id_ex_mem_write, id_ex_mem_to_reg, id_ex_reg_write, id_ex_alu_src})
108+ .d({if_id_pc, reg_read_data1, reg_read_data2, if_id_instruction, branch, mem_read, mem_write, mem_to_reg, reg_write, alu_src, if_id_nop_instruction }),
109+ .q({id_ex_pc, id_ex_reg_read_data1, id_ex_reg_read_data2, id_ex_instruction, id_ex_branch, id_ex_mem_read, id_ex_mem_write, id_ex_mem_to_reg, id_ex_reg_write, id_ex_alu_src, id_ex_nop_instruction })
105110 );
106111
107112 // ALU ke signals
@@ -132,14 +137,14 @@ module cpu_pipelined(
132137 // EX/MEM Pipeline Register
133138 wire [63 :0 ] ex_mem_pc, ex_mem_alu_result, ex_mem_reg_read_data2, ex_mem_branch_target;
134139 wire [31 :0 ] ex_mem_instruction;
135- wire ex_mem_zero, ex_mem_branch, ex_mem_mem_read, ex_mem_mem_write, ex_mem_mem_to_reg, ex_mem_reg_write;
140+ wire ex_mem_zero, ex_mem_branch, ex_mem_mem_read, ex_mem_mem_write, ex_mem_mem_to_reg, ex_mem_reg_write, ex_mem_nop_instruction ;
136141
137142 ex_mem_register ex_mem (
138143 .clk(clk),
139144 .reset(reset),
140145 .en(1'b1 ),
141- .d({id_ex_pc , alu_result , id_ex_reg_read_data2 , branch_target , id_ex_instruction , zero , id_ex_branch , id_ex_mem_read , id_ex_mem_write , id_ex_mem_to_reg , id_ex_reg_write}),
142- .q({ex_mem_pc, ex_mem_alu_result, ex_mem_reg_read_data2, ex_mem_branch_target, ex_mem_instruction, ex_mem_zero, ex_mem_branch, ex_mem_mem_read, ex_mem_mem_write, ex_mem_mem_to_reg, ex_mem_reg_write})
146+ .d({id_ex_pc , alu_result , id_ex_reg_read_data2 , branch_target , id_ex_instruction , zero , id_ex_branch , id_ex_mem_read , id_ex_mem_write , id_ex_mem_to_reg , id_ex_reg_write , id_ex_nop_instruction }),
147+ .q({ex_mem_pc, ex_mem_alu_result, ex_mem_reg_read_data2, ex_mem_branch_target, ex_mem_instruction, ex_mem_zero, ex_mem_branch, ex_mem_mem_read, ex_mem_mem_write, ex_mem_mem_to_reg, ex_mem_reg_write, ex_mem_nop_instruction })
143148 );
144149
145150 wire branch_taken; // jump karna hai ya nahi
@@ -163,19 +168,22 @@ module cpu_pipelined(
163168 // MEM/WB Pipeline Register
164169 wire [63 :0 ] mem_wb_mem_read_data, mem_wb_alu_result;
165170 wire [31 :0 ] mem_wb_instruction;
166- wire mem_wb_mem_to_reg, mem_wb_reg_write;
171+ wire mem_wb_mem_to_reg, mem_wb_reg_write, mem_wb_nop_instruction ;
167172
168173 mem_wb_register mem_wb (
169174 .clk(clk),
170175 .reset(reset),
171176 .en(1'b1 ),
172- .d({mem_read_data , ex_mem_alu_result, ex_mem_instruction, ex_mem_mem_to_reg, ex_mem_reg_write}),
173- .q({mem_wb_mem_read_data, mem_wb_alu_result, mem_wb_instruction, mem_wb_mem_to_reg, mem_wb_reg_write})
177+ .d({mem_read_data , ex_mem_alu_result, ex_mem_instruction, ex_mem_mem_to_reg, ex_mem_reg_write, ex_mem_nop_instruction }),
178+ .q({mem_wb_mem_read_data, mem_wb_alu_result, mem_wb_instruction, mem_wb_mem_to_reg, mem_wb_reg_write, mem_wb_nop_instruction })
174179 );
175180
176181
177182 // register me value write back karo
178183 assign reg_write_data = mem_wb_mem_to_reg ? mem_wb_mem_read_data : mem_wb_alu_result; // memory se ya ALU se value select karo
179184 assign rd = mem_wb_instruction[11 :7 ]; // destination register ka number
180185
186+ // end_program signal
187+ assign end_program = mem_wb_nop_instruction;
188+
181189endmodule
0 commit comments