我有这段用于lifo内存的代码,我不明白为什么在27行(if( end = n-2)那么完整的<= '1';end if;) 最后一个信号不等于n-1。如果有人能向我解释的话,我会非常感激的。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity lifo is
generic(n : natural := 4);
port(Din : in std_logic_vector(3 downto 0);
Dout : out std_logic_vector(3 downto 0);
wr : in std_logic;
rd : in std_logic;
empty, full : out std_logic;
clk : in std_logic);
end entity lifo;
architecture arh of lifo is
type memorie is array(0 to n-1) of std_logic_vector(3 downto 0);
signal mem : memorie := (others => (others => '0'));
signal last : integer range -1 to n-1;
begin
process(clk)
begin
if (rising_edge(clk)) and (wr = '1') then
if (last = n-1) then null;
else
if(last = n-2) then full <= '1'; end if;
if(last = -1) then empty <= '0'; end if;
mem(last + 1) <= Din;
last <= last + 1;
end if;
elsif (rising_edge(clk)) and (rd = '1') then
if(last = -1) then null;
else
Dout <= mem(last);
last <= last - 1; full <= '0';
if(last = -1) then empty <= '1'; end if;
end if;
end if;
end process;
end architecture arh;发布于 2014-05-31 18:12:21
last在range -1 to n-1中,当last为n-1时,它指示完全的LIFO,而full必须是高的('1')。
当一个写被接受时,last就会与last <= last + 1一起增加1。在同一上升的clk边缘上,决定了full是否应该走高,如果这样写将使LIFO满。写入后,last的值为last+1 (接受写入时为+1 ),如果为n-1,则LIFO为满( n-1表示为full)。所以在写完之后,完整的条件是最后+1=n-1,然后写成last = n-2。
此外,如果代码不能立即工作,可以通过几种方式改进代码,例如单个rising_edge(clk)、添加重置、通过否定条件跳过null语句、在同一周期内添加对写和读操作的处理、删除死代码(最后的if)。
https://stackoverflow.com/questions/23973346
复制相似问题