pp.204-206
4ビット×4本のなかから1本を選ぶマルチプレクサを作る。
/* user_defined_type_pkgという名前のパッケージを作る。 そのなかでbv_arrayという型(1D X 1D)を定義する。 range <>は範囲がunconstrainedであるということ。 */ package user_defined_type_pkg is type bv_array is array (natural range <>) of bit_vector; end package; -- workはプロジェクトディレクトリー(workライブラリー)のこと use work.user_defined_type_pkg.all; -- 4ビット幅×4本の中から1本を選ぶマルチプレクサを作る。 entity mux_generic is generic( NUM_INPUTS : natural := 4; -- 4本 NUM_BITS : natural := 4 -- 4ビット幅 ); -- 回路ポートの型はstd_logicのほうが望ましいが、ここではコードをシンプルにしたいので使っていない。 port( -- インデックス(0~3)、4ビット幅の排列を作る。 a : in bv_array(0 to NUM_INPUTS-1)(NUM_BITS-1 downto 0); sel : in natural range 0 to NUM_INPUTS-1; b : out bit_vector(NUM_BITS-1 downto 0) ); end entity; architecture rtl of mux_generic is begin b <= a(sel); end architecture;