pp.255-256
前回と同じことを今度はcomponent実体化オプションで再現する。componentの実体化はarchitectureボディの宣言部でもよいしgenerateステートメントの宣言部でも良い。
- architectureボディの宣言部でcomponentを実体化する場合:
library ieee; use ieee.std_logic_1164.all; entity carry_ripple_adder is generic( NUM_BITS : natural := 4 -- ビット数(全加算器の個数) ); port( a, b : in std_logic_vector(NUM_BITS-1 downto 0); cin : in std_logic; sum : out std_logic_vector(NUM_BITS-1 downto 0); cout : out std_logic ); end entity; architecture rtl of carry_ripple_adder is signal c : std_logic_vector(0 to NUM_BITS); -- full_adder_unitを1個実体化して、 component full_adder_unit is port( a, b, cin: in std_logic; sum, cout: out std_logic ); end component; begin c(0) <= cin; -- それをN個作ってポートを割り当てる。 gen_adder : for i in 0 to NUM_BITS-1 generate adder : full_adder_unit port map(a(i), b(i), c(i), sum(i), c(i+1)); end generate; cout <= c(NUM_BITS); end architecture;
- genarateステートメントの宣言部でcomponentを実体化する場合:
library ieee; use ieee.std_logic_1164.all; entity carry_ripple_adder is generic( NUM_BITS : natural := 4 -- ビット数(全加算器の個数) ); port( a, b : in std_logic_vector(NUM_BITS-1 downto 0); cin : in std_logic; sum : out std_logic_vector(NUM_BITS-1 downto 0); cout : out std_logic ); end entity; architecture rtl of carry_ripple_adder is signal c : std_logic_vector(0 to NUM_BITS); begin c(0) <= cin; -- full_adder_unitを1個実体化して、 -- それをN個作ってポートを割り当てる。 gen_adder : for i in 0 to NUM_BITS-1 generate component full_adder_unit is port( a, b, cin: in std_logic; sum, cout: out std_logic ); end component; begin adder : full_adder_unit port map(a(i), b(i), c(i), sum(i), c(i+1)); end generate; cout <= c(NUM_BITS); end architecture;