GENERATE
It is another concurrent statement (along with operators and WHEN). It is equivalent to the sequential statement LOOP in the sense that it
allows a section of code to be repeated a number of times, thus creating several instances of the same assignments.
1) FOR / GENERATE: notice that GENERATE must be labeled.
label: FOR identifier IN range GENERATE (concurrent assignments) END GENERATE;
2) IF/GENERATE
An irregular form is also available, which uses IF/GENERATE (with an IF equivalent; recall that originally IF is a sequential statement). Here ELSE is not allowed.
label1: FOR identifier IN range GENERATE ... label2: IF condition GENERATE (concurrent assignments) END GENERATE; ... END GENERATE;
Example 1
SIGNAL x: BIT_VECTOR (7 DOWNTO 0); SIGNAL y: BIT_VECTOR (15 DOWNTO 0); SIGNAL z: BIT_VECTOR (7 DOWNTO 0); ... G1: FOR i IN x'RANGE GENERATE z(i) <= x(i) AND y(i+8); END GENERATE;
Example 2 Vector Shifter
The output vector must be a shifted version of the input vector, with twice its width and an amount of shift specified by another input.
For example, if the input bus has width 4, and the present value is ‘‘1111’’, then the output should be one of the lines of the following
matrix (the original vector is underscored):
row(0): 0 0 0 0 1 1 1 1
row(1): 0 0 0 1 1 1 1 0
row(2): 0 0 1 1 1 1 0 0
row(3): 0 1 1 1 1 0 0 0
row(4): 1 1 1 1 0 0 0 0
1 ------------------------------------------------ 2 LIBRARY ieee; 3 USE ieee.std_logic_1164.all; 4 ------------------------------------------------ 5 ENTITY shifter IS 6 PORT ( inp: IN STD_LOGIC_VECTOR (3 DOWNTO 0); 7 sel: IN INTEGER RANGE 0 TO 4; 8 outp: OUT STD_LOGIC_VECTOR (7 DOWNTO 0)); 9 END shifter; 10 ------------------------------------------------ 11 ARCHITECTURE shifter OF shifter IS 12 SUBTYPE vector IS STD_LOGIC_VECTOR (7 DOWNTO 0); 13 TYPE matrix IS ARRAY (4 DOWNTO 0) OF vector; 14 SIGNAL row: matrix; 15 BEGIN 16 row(0) <= "0000" & inp; 17 G1: FOR i IN 1 TO 4 GENERATE 18 row(i) <= row(i-1)(6 DOWNTO 0) & '0'; 19 END GENERATE; 20 outp <= row(sel); 21 END shifter; 22 ------------------------------------------------