-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifo.v
54 lines (48 loc) · 1.16 KB
/
lifo.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// LIFO (stack) memory module made with D-Latches
`include "dlatch.v"
`include "mult2to1.v"
module LIFO
#(
parameter int WIDTH = 8,
parameter int DEPTH = 8
)
(
input logic clkin,
input logic rst,
input logic psh,
input logic pll,
input logic [WIDTH-1:0] in,
output logic [WIDTH-1:0] out,
output logic full
);
// Clock
logic clk;
assign clk = clkin && (psh || pll);
// Internal wiring
logic [WIDTH-1:0] dlatchout[DEPTH-1:0];
logic [WIDTH-1:0] dlatchin[DEPTH-1:0];
// Generate memory
genvar i;
generate
for(i = 0; i < DEPTH; i = i + 1) begin
// Generate multiplexer
Mult2To1#(.WIDTH(WIDTH)) mult(
.in_a(i < DEPTH-1 ? dlatchout[i+1] : '0),
.in_b(i > 0 ? dlatchout[i-1] : in),
.ctrl(psh),
.out(dlatchin[i])
);
// Generate DLatch
DLatch#(.WIDTH(WIDTH)) dlatch(
.clk(clk),
.rst(rst),
.d(dlatchin[i]),
.q(dlatchout[i])
);
end
endgenerate
// Out tristate buffer
assign out = pll ? dlatchout[0] : 'z;
// Check full
assign full = |dlatchout[DEPTH-1];
endmodule