8.8.8 Case statement
“If a signal or variable is assigned values in some branches of a case statement, but not in all cases, then level-sensitive storage elements may result (see 6.2). This is true only if the assignment does not occur under the control of a clock edge.”
entity RANGE_1 is
port (A,B: in integer range 0 to 15;
C,X: in integer range 0 to 15;
Z : out integer range 0 to 15);
end RANGE_1;
architecture EXAMPLE of RANGE_1 is
begin
process (A, B, C, X)
begin
case X is
when 0 =>
Z <= A;
when 7 | 9 =>
Z <= B;
when 1 to 5 =>
Z <= C;
when others =>
Z <= 0;
end case;
end process;
end EXAMPLE;
entity RANGE_2 is
port(A,B: in bit_vector(3 downto 0);
C,X: in bit_vector(3 downto 0);
Z : out bit_vector(3 downto 0));
end RANGE_2;
architecture EXAMPLE of RANGE_2 is
begin
process (A, B, C, X)
begin
case X is
when "0000" =>
Z <= A;
when "0111" | "1001" =>
Z <= B;
when "0001" to "0101"=> -- wrong
Z <= C;
when others =>
Z <= 0;
end case;
end process;
end EXAMPLE;
The sequence of values is undefined for arrays
Notes
Ranges can be defined for data types with a fixed order, only, e.g. user defined enumerated types or integer values. This way, it can be decided whether one value is less than, equal to or greater than another value. For array types (e.g. a ’bit_vector’) there is no such order, i.e. the ’range “0000” to “0100”’ is undefined and therefore not admissible.