library ieee; use ieee.std_logic_1164.all; entity sync_reg8 is port ( clk: in std_logic; d: in std_logic_vector(7 downto 0); q: out std_logic_vector(7 downto 0) ); end sync_reg8; architecture arch of sync_reg8 is begin process (clk) begin if (clk'event and clk = '1') then if (rst = '0') then q <= "00000000"; else q <= d; end if; end if; end process; end arch;process文の中のif文の中で、「'event」という記述がありますが、 これは、clkのエッジ、つまり0→1に変わるタイミング、あるいは逆に0→1に 変わるタイミング、のときに真になります。 つまり、その条件と、もう1つのclK='1'で、clkが0→1に変わる 立ち上がりをとらえていることになります。
library ieee; use ieee.std_logic_1164.all; entity async_reg8 is port ( clk: in std_logic; d: in std_logic_vector(7 downto 0); q: out std_logic_vector(7 downto 0) ); end async_reg8; architecture arch of async_reg8 is begin process (clk, rst) begin if (rst == '0') then q <= "00000000"; elseif (clk'event and clk = '1') then q <= d; end if; end process; end arch;さきほどの同期リセットつきレジスタの場合との違いに注意しておきましょう。
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity count8 is port ( clk: in std_logic; q: out std_logic_vector(7 downto 0); ); end count8; architecture arch of count8 is signal q_reg: std_logic_vector(7 downto 0); begin process (clk) begin if (clk'event and clk = '1') then if (rst = '0') then q_reg <= "00000000"; else q_reg <= q_reg + 1; end if; end if; end process; q <= q_reg; end arch;基本的には、レジスタの場合と同じで、クロックの立ち上がりに、 値を1ずつ足している、つまり出力の値が1ずつ増えていく、という動作を していることに注意しておきましょう。
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; entity regfile is port ( clk, rst: in std_logic; d: in std_logic_vector(7 downto 0); n: in std_logic_vector(2 downto 0); w: in std_logic; q: out std_logic_vector(7 downto 0); ); end regfile; architecture arch of regfile is type t_reg_f is array (integer range 0 to 7) of std_logic_vector(7 downto 0); signal regf: t_regf; begin process (clk) begin if (clk'event and clk = '1') then if (rst = '0') then for i in 0 to 7 loop regf(i) <= "00000000"; end loop; elsif (w = '1') then regf(to_integer(n)) <= d; end if; end if; end process; q <= regf(to_integer(n)); end arch;typeという、型宣言を行う記述が出てきました。 t_reg_fという型を、1バイトのデータ(std_logic_vector(7 downto 0))の、 添え字が0〜7の配列という型として定義して、 その型のregfという名前のsignalを宣言して、これをレジスタファイルとして 使っています。
clkの立ち上がり時に、w=1ならばn番目のレジスタに書き込み、 また出力qに、n番目のレジスタの値が出力されています。