1

最初に、この単純な加算エンティティがあります。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_misc.all;
use ieee.numeric_std.all;

entity adder is
    Port ( a : in  STD_LOGIC_VECTOR(31 downto 0);
           b : in  STD_LOGIC_VECTOR(31 downto 0);
           alu_out : out  STD_LOGIC_VECTOR(31 downto 0) := (others => '0')
           );
end adder;

architecture Behavioral of adder is
  signal result_ext:STD_LOGIC_VECTOR(32 downto 0) := (others => '0');
  signal result:STD_LOGIC_VECTOR(31 downto 0)     := (others => '0');
begin

  process (a,b)
  begin
    result_ext <= std_logic_vector(signed('0' & a) + signed('0' & b));
    result     <= result_ext(result'left downto 0);

    alu_out <= result;
  end process;
end Behavioral;

そしてテストベンチ:

-- TestBench Template 

  LIBRARY ieee;
  USE ieee.std_logic_1164.ALL;
  USE ieee.numeric_std.ALL;

  ENTITY testbench IS
  END testbench;

  ARCHITECTURE behavior OF testbench IS         

    signal a : STD_LOGIC_VECTOR(31 downto 0);
    signal b : STD_LOGIC_VECTOR(31 downto 0);
    signal alu_out : STD_LOGIC_VECTOR(31 downto 0);
  BEGIN
    ADDER : entity work.adder port map(
      a => a,
      b => b,
      alu_out => alu_out
    );



  --  Test Bench Statements
     tb : PROCESS
     BEGIN

        a <= B"0000_0000_0000_0000_0000_0000_0111_1010";
        b <= B"0000_0000_0000_0000_0000_0000_0000_1011";

        wait for 100 ns; -- wait until global set/reset completes

        report "alu_out = " & integer'image(to_integer(signed(alu_out)));

        wait; -- will wait forever
     END PROCESS tb;
  --  End Test Bench 

  END;

レポート出力を取得します:

Finished circuit initialization process.
at 100 ns: Note: alu_out = 0 (/testbench/).

結果信号を初期化しないと、未定義になります。問題は、最終的に結果が得られないことです。

iSimザイリンクスを使用しています。

また、誰かが VHDL に関する簡潔で効果的な資料への適切なリンクを持っている場合は、遠慮なく投稿してください。

4

2 に答える 2

2

ピーターのコードを取り、:

  • 入力幅の柔軟性を更新する
  • ただnumeric_std
  • キャリービットを維持する

これを与える:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;

entity adder is
    generic (width : integer := 32)
    Port ( a       : in  signed(width-1 downto 0);
           b       : in  signed(width-1 downto 0);
           alu_out : out signed(width downto 0) := (others => '0');
           );
end adder;

architecture synth of adder is
begin
  process (a,b)
  begin
    alu_out <= resize(a,alu_out'length) + b;
  end process;
end Behavioral;
于 2012-05-15T12:27:48.373 に答える
1

問題は、プロセスのそのサイクルの即時の値が必要な場合にシグナルを使用していることですresultresult_ext変数はすぐに更新され、プロセスの現在のサイクルでその値にアクセスできます。

これを試してみてください。あなたが抱えている問題を解決すると思います:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;

entity adder is
    Port ( a : in  STD_LOGIC_VECTOR(31 downto 0);
           b : in  STD_LOGIC_VECTOR(31 downto 0);
           alu_out : out  STD_LOGIC_VECTOR(31 downto 0) := (others => '0')
           );
end adder;

architecture Behavioral of adder is


begin

  process (a,b)
    variable result_ext:STD_LOGIC_VECTOR(32 downto 0) := (others => '0');
    variable result:STD_LOGIC_VECTOR(31 downto 0);
  begin
    result_ext := std_logic_vector(signed('0' & a) + signed('0' & b));
    result     := result_ext(result'left downto 0);

    alu_out <= result;
  end process;
end Behavioral;

読み物に関しては、VHDL クックブックは悪くありません: VHDL クックブック

于 2012-05-15T09:17:39.767 に答える