pp.135-137
genericリストを使って前回のコードを少し書き換える。
-- これがパッケージリスト library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- これがエンティティ宣言 entity add_compare_cell is generic( IN_WIDTH : natural := 3; -- 定数名: 定数型 := 定数 OUT_WIDTH: natural := 4 ); port( a, b: in std_logic_vector(IN_WIDTH-1 downto 0); comp: out std_logic; sum : out std_logic_vector(OUT_WIDTH-1 downto 0) ); end entity; -- これがアーキテクチャーボディ architecture detaflow of add_compare_cell is signal a_uns, b_uns: unsigned(3 downto 0); begin a_uns <= unsigned('0' & a); b_uns <= unsigned('0' & b); comp <= '1' when a_uns > b_uns else '0'; sum <= std_logic_vector(a_uns + b_uns); end architecture;