Search code examples
vhdl

VHDL - AND operation between vector and bit


i'm starting in VHDL, and I have a problem trying add a enable to a port. I have an output vector of 8 bits, and I want to put a value if the "Enable"bit input is '1'. Else, put a '0' in the vector.

I can make:

out(0) <= '0' AND Enable;
out(1) <= '0' AND Enable;
out(2) <= '1' AND Enable;
out(3) <= '0' AND Enable;
out(4) <= '1' AND Enable;
...
out(7) <= '0' AND Enable;

There are a easy way to make this? I'm thinking like: out <= "01010100" AND Enable; but it doesn't work...

I can use an "if", but i prefer use this way to understand how to do it.


Solution

  • A tidy way to do this is with a conditional signal assignment:

    Out <= Value when Enable = '1' else (others=>'0');
    

    ...as a bonus, you can assign any value you want (even a different signal vector) when Enable is low.