Sample: your first entity (2-to-1 MUX)
A multiplexer is the simplest combinational device that has a "choice" in it. The 2-to-1 version selects between two inputs based on one sel bit:
sel = 0 → y = a
sel = 1 → y = b
The VHDL for that is one line:
y <= a when sel = '0' else b;
What the sample does
Open the sample and you'll get a project named Your first entity with:
mux21.vhd(the design above)- A companion simulation config that drives
sel,a, andbover 40 microseconds
When you Run, the Waveforms tab shows four rows — the three inputs and the output. Watch y flip between a and b as sel toggles.
Things to notice
The assignment y <= a when sel = '0' else b; is a concurrent statement: it lives outside of any process, and it describes a permanent wiring. There's no "when does this line execute?" — it just is.
The condition inside a when/else can be any boolean expression:
y <= a when sel = '0' else
b when enable = '1' else
'Z';
Chains like that synthesize to a priority multiplexer (top case wins ties).
Your turn: extend it
Once you've seen the sample work:
- Change the entity to a 4-to-1 MUX —
selbecomes 2 bits, and you choose betweena,b,c,d. - Add a fifth port
output_enable. When it's'0', drivey <= 'Z'(high impedance) regardless ofsel. - Compare
when/elseagainst thewith/selectversion you'll meet in the next module.
Kmila's editor highlights the VHDL keywords and knows about std_logic — hover over when to see the built-in documentation.