0

私はこのコードを lifo メモリ用に持っていますが、27 行 (if(last = n-2) then full <= '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;
4

1 に答える 1

1

lastrange -1 to n-1あり、lastが n-1 の場合は LIFO がフルであることを示し、fullハイである必要があります ( '1')。

書き込みが受け付けられると、 thenlastは で 1 インクリメントされlast <= last + 1ます。同じ立ち上がりclkエッジでfull、ハイになるかどうかが決定されます。これは、この書き込みによって LIFO がフルになる場合です。書き込み後last、値は last+1 (書き込みが受け入れられた場合は +1) になり、n-1 (n-1 はフルを示す) に等しい場合、LIFO はフルです。したがって、この書き込み後の full の条件は last+1=n-1 であり、これは次のように書き込まれlast = n-2ます。

さらに、コードがすぐに機能しない場合は、いくつかの方法でコードを改善することができます。たとえば、 single rising_edge(clk)、リセットの追加、否定条件によるステートメントのスキップ、null同じサイクルでの書き込み操作と読み取り操作の処理の追加、デッド コードの削除 (最終if)。

于 2014-05-31T18:12:21.053 に答える