pp.149-151
6.1 設計単位とコード構造と / 和と比較と -と同じ回路の出力を、今度はDFFに通す。
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity add_compare_registered is generic( NUM_BITS: natural := 8 ); port( clk: in std_logic; a, b: in std_logic_vector(NUM_BITS-1 downto 0); comp: out std_logic; sum: out std_logic_vector(NUM_BITS downto 0) ); end entity; architecture rtl of add_compare_registered is signal a_uns, b_uns: unsigned(NUM_BITS downto 0); begin a_uns <= unsigned('0' & a); b_uns <= unsigned('0' & b); /* 組み合わせ回路の部分(加算器と比較器)はprocessよりも前にコンカレントコードとして記述できるが、 回路全体をカプセル化するモジュールとしてprocessを使うのは一般に良い考えである(p.149)。 */ process(clk) begin if rising_edge(clk) then if a_uns > b_uns then comp <= '1'; else comp <= '0'; end if; sum <= std_logic_vector(a_uns + b_uns); end if; end process; end architecture;