i have the following expression and want so shorten it down to a shorter one.
Can anyone help me?
architecture behavioral of mux4 is
begin
with sel select
y <= "a" when "00",
"b" when "01",
"c" when "10",
"d" when "11",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" when others;
end architecture behavioral
I want to avoid writing 32 time the character X. I know that it can be replaced with another expression but i can't remember.
To shorten the default expression, usually (others => 'X')
will create a value with X
in all unspecified members (here, all members since you haven't specified any bits explicitly.
architecture behavioral of mux4 is
begin
with sel select
y <= "a" when "00",
"b" when "01",
"c" when "10",
"d" when "11",
(others => 'X') when others;
end architecture behavioral;
Note : there are cases where VHDL can't determine the size of the expression from the context, so this won't always work. There is an alternative : since it's obvious you want the value to be the same size as y
, you can create such a value filled with 'X'
very easily using the 'range
attribute, as in:
with sel select
y <= "a" when "00",
(y'range => 'X') when others;