mirror of
https://github.com/supleed2/ELEC40006-P1-CW.git
synced 2024-12-22 21:45:49 +00:00
Update LIFOstack to support 32 memory slots
Also fixed typo on line 15, previous version had a pointer for 16 slots but the memory register only had 4 slots
This commit is contained in:
parent
42739283f5
commit
94124c5a0e
12
LIFOstack.v
12
LIFOstack.v
|
@ -10,18 +10,18 @@ output reg [15:0] Dout; // Data being pulled from stack
|
||||||
output reg empty; // goes high to indicate SP is at 0
|
output reg empty; // goes high to indicate SP is at 0
|
||||||
output reg full; // goes high to indicate SP is at (slots)
|
output reg full; // goes high to indicate SP is at (slots)
|
||||||
|
|
||||||
reg [4:0] SP; // Points to slot to save next value to
|
reg [5:0] SP; // Points to slot to save next value to
|
||||||
integer i;
|
integer i;
|
||||||
reg [15:0] mem [3:0];
|
reg [15:0] mem [31:0];
|
||||||
|
|
||||||
always @ (posedge clk) begin
|
always @ (posedge clk) begin
|
||||||
if (!en); // if not enabled, ignore this cycle
|
if (!en); // if not enabled, ignore this cycle
|
||||||
else begin
|
else begin
|
||||||
if (rst) begin // if rst is high, clear memory and reset pointers/outputs
|
if (rst) begin // if rst is high, clear memory and reset pointers/outputs
|
||||||
Dout = 16'h0000;
|
Dout = 16'h0000;
|
||||||
SP = 4'b0000;
|
SP = 6'b000000;
|
||||||
empty = 1'b1;
|
empty = 1'b1;
|
||||||
for (i = 0; i < 16; i = i + 1) begin
|
for (i = 0; i < 32; i = i + 1) begin
|
||||||
mem[i] = 16'h0000;
|
mem[i] = 16'h0000;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ always @ (posedge clk) begin
|
||||||
if (!full && rw) begin // Write when NOT full & Writing
|
if (!full && rw) begin // Write when NOT full & Writing
|
||||||
mem[SP] = Din; // Store data into current slot
|
mem[SP] = Din; // Store data into current slot
|
||||||
SP = SP + 1'b1; // Increment stack pointer to next empty slot
|
SP = SP + 1'b1; // Increment stack pointer to next empty slot
|
||||||
full = (SP == 5'b10000) ? 1 : 0; // Stack is full if SP is (slots)
|
full = (SP == 6'b100000) ? 1 : 0; // Stack is full if SP is (slots)
|
||||||
empty = 1'b0; // Stack is never empty after a push
|
empty = 1'b0; // Stack is never empty after a push
|
||||||
end
|
end
|
||||||
else if (!empty && !rw) begin // Read when NOT empty & reading
|
else if (!empty && !rw) begin // Read when NOT empty & reading
|
||||||
|
@ -37,7 +37,7 @@ always @ (posedge clk) begin
|
||||||
Dout = mem[SP]; // Output data from last filled slot
|
Dout = mem[SP]; // Output data from last filled slot
|
||||||
mem[SP] = 16'h0000; // Clear slot after setting output
|
mem[SP] = 16'h0000; // Clear slot after setting output
|
||||||
full = 1'b0; // Stack is never full after a pop
|
full = 1'b0; // Stack is never full after a pop
|
||||||
empty = (SP == 5'b00000) ? 1 : 0; // Stack is empty if SP is 0
|
empty = (SP == 6'b000000) ? 1 : 0; // Stack is empty if SP is 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue