📄 lifo.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity lifo is
port(clr:in std_logic;--------清零信号
push:in std_logic;-------压栈信号
pop:in std_logic;--------出栈信号
clk:in std_logic;--------时钟信号
din:in std_logic_vector(7 downto 0);------数据输入端
empty:out std_logic;-----栈空信号
full:out std_logic;------栈满信号
dout:out std_logic_vector(7 downto 0));---数据输出端
end;
architecture one of lifo is
type memory is array(0 to 8)of std_logic_vector(7 downto 0);----存储空间
begin
process(clk,clr)
variable stack:memory;
variable cnt:integer range 0 to 8;----设置指针,栈底指针为0
begin
if clr='1' then----------------------------------清零
dout<=(others=>'0');
full<='0';
cnt:=0;
elsif clk'event and clk='1' then
if push='1' and pop='0' and cnt/=8 then-----------压栈
empty<='0';
stack(cnt):=din;--------------------存入数据
cnt:=cnt+1;-------------------------指针加1
elsif pop='1' and push='0' and cnt/=0 then---------出栈
full<='0';
cnt:=cnt-1;-------------------------指针减1
dout<=stack(cnt);-------------------输出数据
elsif cnt=0 then
empty<='1';
dout<=(others=>'0');
elsif cnt=8 then
full<='1';
end if;
end if;
end process;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -