Fix program counter taking two cycles for each instr

This commit is contained in:
jl7719 2020-12-15 15:53:30 +00:00
parent 01a3b9a973
commit 85efff275a
2 changed files with 12 additions and 8 deletions

View file

@ -56,7 +56,7 @@ module mips_cpu_memory(
//Synchronous write path //Synchronous write path
always_ff @(posedge clk) begin always_ff @(posedge clk) begin
$display("Instruction Read: %h", instr_readdata); //$display("Instruction Read: %h", instr_readdata);
//$display("RAM : INFO : data_read=%h, data_address = %h, mem=%h", data_read, data_address, memory[data_address]); //$display("RAM : INFO : data_read=%h, data_address = %h, mem=%h", data_read, data_address, memory[data_address]);
if (data_write) begin //cannot read and write to memory in the same cycle if (data_write) begin //cannot read and write to memory in the same cycle
if (instr_address != data_address) begin //cannot modify the instruction being read if (instr_address != data_address) begin //cannot modify the instruction being read

View file

@ -26,25 +26,29 @@ always_ff @(posedge clk) begin
active <= 0; active <= 0;
end end
pc_out <= pc_next; pc_out <= pc_next;
case(pc_ctrl)
default: begin
pc_next <= pc_out + 32'd4;
end end
end
always_comb begin
case(pc_ctrl)
2'd1: begin // Branch 2'd1: begin // Branch
pc_next <= pc_out + 32'd4 + {{14{instr[15]}},instr[15:0],2'b00}; pc_next = pc_out + 32'd4 + {{14{instr[15]}},instr[15:0],2'b00};
end end
2'd2: begin // Jump 2'd2: begin // Jump
pc_next <= {pc_lit_next[31:28], instr[25:0], 2'b00}; pc_next = {pc_lit_next[31:28], instr[25:0], 2'b00};
$display("JUMPING"); $display("JUMPING");
$display("pc_lit_next: %h", pc_lit_next[31:28]); $display("pc_lit_next: %h", pc_lit_next[31:28]);
$display("instr: %b", instr[25:0]); $display("instr: %b", instr[25:0]);
$display("%h",pc_next); $display("%h",pc_next);
end end
2'd3: begin // Jump using Register 2'd3: begin // Jump using Register
pc_next <= reg_readdata; pc_next = reg_readdata;
end
default: begin
pc_next = pc_out + 32'd4;
end end
endcase endcase
end end
end
endmodule // pc endmodule // pc