首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LIFO内存vhdl代码理解

LIFO内存vhdl代码理解
EN

Stack Overflow用户
提问于 2014-05-31 17:45:23
回答 1查看 4.2K关注 0票数 0

我有这段用于lifo内存的代码,我不明白为什么在27行(if( end = n-2)那么完整的<= '1';end if;) 最后一个信号不等于n-1。如果有人能向我解释的话,我会非常感激的。

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-31 18:12:21

lastrange -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)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23973346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档