-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path15_stack_mem.v
67 lines (60 loc) · 1.05 KB
/
15_stack_mem.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
55
56
57
58
59
60
61
62
63
64
65
66
67
//A memory according to stack
//author:WangFW
//date:2020-5-23
module stack_mem(clk,rst_n,en,wr,rd,din,dout,full,empty);
input clk;
input rst_n;
input en;
input wr;
input rd;
input [7:0] din;
output reg full;
output reg empty;
output reg [7:0] dout;
reg [7:0] mem [31:0];
reg [4:0] point;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
full<=1'b0;
empty<=1'b0;
dout<=8'd0;
point=5'd0;
end
else
if(en)
begin
if(wr)
begin
if(point<5'd31)
begin
mem[point]<=din;
point<=point+1'b1;
full<=1'b0;
empty<=1'b0;
end
else
begin
full<=1'b1;
empty<=1'b0;
end
end
if(rd)
begin
if(point>5'd0)
begin
dout<=mem[point];
point=point-1'b1;
empty<=1'b0;
full<=1'b0;
end
else
begin
empty<=1'b1;
full<=1'b0;
end
end
end
end
endmodule