mirror of
https://github.com/supleed2/ELEC50010-IAC-CW.git
synced 2024-12-23 05:45:47 +00:00
PC logic updated
PC now has a delay into instr_mem to match MIPS32 spec and pc resets/initialises to MIPS32 reset vector
This commit is contained in:
parent
10af46a352
commit
f2f8e05010
|
@ -33,7 +33,7 @@ logic[31:0] Jump_addr = {{pc_curr+4}[31:28], instr_readdata[25:0], 2'b00};
|
||||||
logic PCSrc = Branch && ALUZero;
|
logic PCSrc = Branch && ALUZero;
|
||||||
|
|
||||||
//Instruction MEM
|
//Instruction MEM
|
||||||
assign instr_address = pc_curr;
|
assign instr_address = pc_delay;
|
||||||
|
|
||||||
//deconstruction of instruction :)
|
//deconstruction of instruction :)
|
||||||
logic[5:0] opcode = instr_readdata[31:26];
|
logic[5:0] opcode = instr_readdata[31:26];
|
||||||
|
@ -56,8 +56,13 @@ assign data_writedata = read_data2; //data to be written comes from reg read bus
|
||||||
//Writeback logic
|
//Writeback logic
|
||||||
logic[31:0] writeback = MemtoReg==2'b10 ? {pc_curr+4} : MemtoReg==2'b01 ? data_readdata : ALUOut;
|
logic[31:0] writeback = MemtoReg==2'b10 ? {pc_curr+4} : MemtoReg==2'b01 ? data_readdata : ALUOut;
|
||||||
|
|
||||||
|
always_ff @(posedge clk) begin
|
||||||
|
pc_delay <= pc_curr;
|
||||||
|
end
|
||||||
|
|
||||||
pc pc(
|
pc pc(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
|
.rst(reset),
|
||||||
.pc_in(pc_next),
|
.pc_in(pc_next),
|
||||||
.pc_out(pc_curr)
|
.pc_out(pc_curr)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,43 +1,25 @@
|
||||||
module ProgramCounter(
|
module pc(
|
||||||
|
|
||||||
input logic rst,
|
|
||||||
input logic clk,
|
input logic clk,
|
||||||
|
input logic rst,
|
||||||
input logic[31:0] pcWriteAddr,
|
input logic[31:0] pc_in,
|
||||||
input logic pcWriteEn,
|
output logic[31:0] pc_out
|
||||||
|
|
||||||
output logic[31:0] pcRes,
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
logic[31:0] pcIncr;
|
reg[31:0] pc_curr;
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
|
pc_curr = 32'hBFC00000;
|
||||||
pcRes <= 32'h00000000;
|
end : initial
|
||||||
end
|
|
||||||
|
|
||||||
always_comb begin
|
always_comb begin
|
||||||
pcIncr = pcRes + 32'h00000004
|
if (rst) begin
|
||||||
|
pc_curr = 32'hBFC00000;
|
||||||
|
end
|
||||||
|
pc_out = pc_curr;
|
||||||
end
|
end
|
||||||
|
|
||||||
always @(posedge clk)
|
always_ff @(posedge clk) begin
|
||||||
begin
|
pc_curr <= pc_in;
|
||||||
if (rst == 1)
|
|
||||||
begin
|
|
||||||
pcRes <= 32'h00000000;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
if (pcWriteEn == 1) begin
|
|
||||||
pcRes <= pcWriteAddr;
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
pcRes <= pcIncr;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
$display("pc = %h",pcRes);
|
endmodule : pc
|
||||||
end
|
|
||||||
|
|
||||||
endmodule
|
|
Loading…
Reference in a new issue