@@ -28,34 +28,36 @@ module cpu_pipelined(
2828 .clk(clk),
2929 .reset(reset),
3030 .next_pc(pc_next), // agli instruction ka address
31+ .stall(branch_stall),
3132 .pc(pc_current) // current instruction ka address
3233 );
3334
35+
3436 // program instructions ko store karta hai
3537 instruction_memory imem ( // REMEMBER INITIALIZED AS imem, so you can do cpu.imem.memory[0] in testbench
3638 .pc(pc_current), // current PC se
3739 .instruction(instruction) // instruction nikalo
3840 );
3941
4042 wire nop_instruction;
41- assign nop_instruction = instruction == 0 ; // no operation instruction
43+ assign nop_instruction = instruction == - 1 ; // no operation instruction
4244
4345 // IF/ID Pipeline Register
4446 wire [63 :0 ] if_id_pc;
4547 wire [31 :0 ] if_id_instruction;
4648 wire if_id_end_instruction, if_id_nop_instruction;
4749
4850 // 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;
51+ wire branch_stall ;
52+ assign branch_stall = if_id_instruction[6 :0 ] == 7'b1100011 ;
53+ wire [31 :0 ] stall_instruction ;
54+ assign stall_instruction = branch_stall ? 32'b00000000000000000000000000000000 : instruction;
5355
5456 if_id_register if_id (
5557 .clk(clk),
5658 .reset(reset),
5759 .en(1'b1 ),
58- .d({pc_current, halt_instruction , nop_instruction}),
60+ .d({pc_current, stall_instruction , nop_instruction}),
5961 .q({if_id_pc , if_id_instruction, if_id_nop_instruction})
6062 );
6163
@@ -154,8 +156,10 @@ module cpu_pipelined(
154156 );
155157
156158 wire branch_taken; // jump karna hai ya nahi
157- assign branch_taken = ex_mem_branch & ex_mem_zero; // branch lena hai ya nahi
158- assign pc_next = branch_taken ? ex_mem_branch_target : (branch_halt? pc_current : pc_current + 4 ); // next PC set karo
159+ assign branch_taken = id_ex_branch & zero; // branch lena hai ya nahi
160+ assign pc_next = branch_taken ? branch_target : id_ex_pc + 4 ; // next PC set karo
161+ // assign branch_taken = ex_mem_branch & ex_mem_zero; // branch lena hai ya nahi
162+ // assign pc_next = branch_taken ? ex_mem_branch_target : ex_mem_pc + 4; // next PC set karo
159163
160164 // memory ke signals
161165 wire signed [63 :0 ] mem_read_data; // memory se padhi hui value
0 commit comments