【VHDL】バレル・シフト回路とrange-based loop
バレル・シフト回路
以下に,バレル・シフト回路のVHDLソースコードを表示する.
-- Barrel Shifter library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; use IEEE.numeric_std.all; entity BShifterNbit is generic (N : integer := 3); port ( A : in std_logic_vector((2**N) - 1 downto 0); S : in std_logic_vector(N - 1 downto 0); Z : out std_logic_vector((2**N) - 1 downto 0) ); end BShifterNbit; architecture RTL of BShifterNbit is begin process(A, S) variable sc : integer; begin sc := to_integer(unsigned(S)); --Debugsc := conv_integer(S); for I in A'range loop --Debug--for I in 0 to 7 Loop if (I + sc <= A'left) then Z(I + sc) <= A(I); else Z(I + sc - A'left - 1) <= A(I); end if; end loop; end process; end RTL;
[引用]range-based loop
for i in a'range loop
...;
end loop;
aの配列またはバスの範囲がある限りiを増加させながらループを繰り返す。
processの中で利用する。