move cpu flags into Flags module
This commit is contained in:
parent
d27def5296
commit
58c8f2e7cb
31
RTL/Flags.sv
Normal file
31
RTL/Flags.sv
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Module Name: Flags
|
||||||
|
// Project Name: CSE141L
|
||||||
|
// Description: flag registers
|
||||||
|
|
||||||
|
module Flags (
|
||||||
|
input logic Clk, Reset, WriteEn, start,
|
||||||
|
input logic Zero_in, Done_in,
|
||||||
|
output logic Zero_out, Done_out
|
||||||
|
);
|
||||||
|
|
||||||
|
logic Zero, Done;
|
||||||
|
|
||||||
|
assign Zero_out = Zero;
|
||||||
|
assign Done_out = Done;
|
||||||
|
|
||||||
|
always_ff @(posedge Clk) begin
|
||||||
|
if(Reset) begin
|
||||||
|
Zero <= 'b0;
|
||||||
|
Done <= 'b1; // default Done to halt machine
|
||||||
|
end
|
||||||
|
else if (start) begin
|
||||||
|
Zero <= Zero_in;
|
||||||
|
Done <= 'b0;
|
||||||
|
end
|
||||||
|
else if (WriteEn) begin
|
||||||
|
Zero <= Zero_in;
|
||||||
|
Done <= Done_in;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
@ -3,23 +3,18 @@
|
|||||||
// Description: register file
|
// Description: register file
|
||||||
|
|
||||||
module RegFile #(parameter W=8, D=4)( // W = data path width (leave at 8); D = address pointer width
|
module RegFile #(parameter W=8, D=4)( // W = data path width (leave at 8); D = address pointer width
|
||||||
input Clk, Reset, WriteEn,
|
input logic Clk, Reset, WriteEn,
|
||||||
input [D-1:0] RaddrA, RaddrB, Waddr, // read anad write address pointers
|
input logic [D-1:0] RaddrA, RaddrB, Waddr, // read anad write address pointers
|
||||||
input [W-1:0] DataIn, // data to be written
|
input logic [W-1:0] DataIn, // data to be written
|
||||||
input logic Zero_in, Done_in, // since flags are stored in register file, need this as an input
|
|
||||||
input logic start, // start signal from testbench
|
input logic start, // start signal from testbench
|
||||||
output logic [W-1:0] DataOutA, DataOutB, // data to read out
|
output logic [W-1:0] DataOutA, DataOutB // data to read out
|
||||||
output logic Zero_out, Done_out // output of zero and done flags
|
|
||||||
);
|
);
|
||||||
|
|
||||||
logic [W-1:0] Registers[2**D]; // 2^D registers of with W
|
logic [W-1:0] Registers[2**D]; // 2^D registers of with W
|
||||||
logic Zero, Done;
|
|
||||||
|
|
||||||
// combination read
|
// combination read
|
||||||
assign DataOutA = Registers[RaddrA];
|
assign DataOutA = Registers[RaddrA];
|
||||||
assign DataOutB = Registers[RaddrB];
|
assign DataOutB = Registers[RaddrB];
|
||||||
assign Zero_out = Zero;
|
|
||||||
assign Done_out = Done;
|
|
||||||
|
|
||||||
// sequential (clocked) writes
|
// sequential (clocked) writes
|
||||||
always_ff @ (posedge Clk) begin
|
always_ff @ (posedge Clk) begin
|
||||||
@ -27,18 +22,12 @@ module RegFile #(parameter W=8, D=4)( // W = data path width (leave at 8); D =
|
|||||||
for(int i=0; i<2**D; i++) begin
|
for(int i=0; i<2**D; i++) begin
|
||||||
Registers[i] <= 'h0;
|
Registers[i] <= 'h0;
|
||||||
end
|
end
|
||||||
Zero <= 'b0;
|
|
||||||
Done <= 'b1; // default Done to halt machine
|
|
||||||
end
|
end
|
||||||
else if (start) begin
|
else if (start) begin
|
||||||
Registers[Waddr] <= DataIn;
|
Registers[Waddr] <= DataIn;
|
||||||
Zero <= Zero_in;
|
|
||||||
Done <= 'b0;
|
|
||||||
end
|
end
|
||||||
else if (WriteEn) begin
|
else if (WriteEn) begin
|
||||||
Registers[Waddr] <= DataIn;
|
Registers[Waddr] <= DataIn;
|
||||||
Zero <= Zero_in;
|
|
||||||
Done <= Done_in;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,13 +59,9 @@ module top_level(
|
|||||||
.RaddrB(RaddrB),
|
.RaddrB(RaddrB),
|
||||||
.Waddr(Waddr),
|
.Waddr(Waddr),
|
||||||
.DataIn(RegInput),
|
.DataIn(RegInput),
|
||||||
.Zero_in(Zero_in),
|
|
||||||
.Done_in(Done_in),
|
|
||||||
.start(req),
|
.start(req),
|
||||||
.DataOutA(RegOutA),
|
.DataOutA(RegOutA),
|
||||||
.DataOutB(RegOutB),
|
.DataOutB(RegOutB)
|
||||||
.Zero_out(Zero_out),
|
|
||||||
.Done_out(Done_out)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
DataMem DM (
|
DataMem DM (
|
||||||
@ -81,6 +77,17 @@ module top_level(
|
|||||||
.InstOut(Instruction)
|
.InstOut(Instruction)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Flags f (
|
||||||
|
.Clk(clk),
|
||||||
|
.Reset(init),
|
||||||
|
.WriteEn(RegWrite),
|
||||||
|
.start(req),
|
||||||
|
.Zero_in(Zero_in),
|
||||||
|
.Zero_out(Zero_out),
|
||||||
|
.Done_in(Done_in),
|
||||||
|
.Done_out(Done_out)
|
||||||
|
);
|
||||||
|
|
||||||
assign ack = Done_out;
|
assign ack = Done_out;
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
Reference in New Issue
Block a user