@@ -45,14 +45,21 @@ module cpu_pipelined(
4545 wire [31 :0 ] if_id_instruction;
4646 wire if_id_end_instruction, if_id_nop_instruction;
4747
48+ // check if_id_instruction to see if it is beq(opcode 1100011), send addi x0 x0 0, also sent pc_next = pc_current
49+ wire branch_halt;
50+ assign branch_halt = if_id_instruction[6 :0 ] == 7'b1100011 ;
51+ wire [31 :0 ] halt_instruction;
52+ assign halt_instruction = branch_halt ? 32'b00000000000000000000000000010011 : instruction;
53+
4854 if_id_register if_id (
4955 .clk(clk),
5056 .reset(reset),
5157 .en(1'b1 ),
52- .d({pc_current, instruction , nop_instruction}),
58+ .d({pc_current, halt_instruction , nop_instruction}),
5359 .q({if_id_pc , if_id_instruction, if_id_nop_instruction})
5460 );
5561
62+
5663 // control signals - CPU ko batate hai kya karna hai
5764 wire branch; // branch instruction hai ya nahi
5865 wire mem_read; // memory se padhna hai
@@ -82,7 +89,6 @@ module cpu_pipelined(
8289 // Register File ke inputs set karo
8390 assign rs1 = if_id_instruction[19 :15 ]; // source register 1 ka number
8491 assign rs2 = if_id_instruction[24 :20 ]; // source register 2 ka number
85- // assign rd = if_id_instruction[11:7]; // destination register ka number
8692
8793 // Register File - CPU ke registers ko handle karta hai
8894 register_file reg_file (
@@ -149,7 +155,7 @@ module cpu_pipelined(
149155
150156 wire branch_taken; // jump karna hai ya nahi
151157 assign branch_taken = ex_mem_branch & ex_mem_zero; // branch lena hai ya nahi
152- assign pc_next = branch_taken ? ex_mem_branch_target : pc_current + 4 ; // next PC set karo
158+ assign pc_next = branch_taken ? ex_mem_branch_target : (branch_halt? pc_current : pc_current + 4 ) ; // next PC set karo
153159
154160 // memory ke signals
155161 wire signed [63 :0 ] mem_read_data; // memory se padhi hui value
0 commit comments