Bird
Raised Fist0
VHDLprogramming~10 mins

Selected assignment (with-select) in VHDL - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Selected assignment (with-select)
Start
↓
Evaluate select expression
↓
Match expression to choice
↓
Choice 1?
Yes→Assign value 1 to target
↓
Choice 2?
Yes→Assign value 2 to target
↓
Others
Yes→Assign default value
↓
End
The selected assignment evaluates an expression and assigns a value based on matching choices, with a default if no match.
Execution Sample
VHDL
with sel select
  out <= "0001" when "00",
         "0010" when "01",
         "0100" when "10",
         "1000" when others;
Assigns a 4-bit output based on 2-bit select input using selected assignment.
Execution Table
Stepsel valueMatched choiceAssigned out valueNotes
1"00""00""0001"sel matches first choice
2"01""01""0010"sel matches second choice
3"10""10""0100"sel matches third choice
4"11"others"1000"sel matches default (others)
5---End of selected assignment execution
💡 All possible sel values matched; assignment complete.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
selundefined"00""01""10""11"varies per step
outundefined"0001""0010""0100""1000"varies per step
Key Moments - 2 Insights
Why does the 'others' choice assign a value when sel is "11"?
Because 'others' covers all values not explicitly listed, so when sel is "11" it matches 'others' as shown in execution_table row 4.
What happens if sel matches multiple choices?
In VHDL selected assignment, sel matches only one choice; the matching choice is used. The execution_table shows unique matches per step.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of 'out' when sel is "10"?
A"0100"
B"1000"
C"0010"
D"0001"
💡 Hint
Check execution_table row 3 under 'Assigned out value'.
At which step does the 'others' choice get assigned?
AStep 1
BStep 3
CStep 4
DStep 2
💡 Hint
Look at execution_table row 4 under 'Matched choice'.
If sel is "01", what will 'out' be assigned according to the execution table?
A"0001"
B"0010"
C"0100"
D"1000"
💡 Hint
Refer to execution_table row 2 for sel "01".
Concept Snapshot
Selected assignment syntax:
with <expression> select
  <target> <= <value1> when <choice1>,
             <value2> when <choice2>,
             ...
             <default_value> when others;

Behavior:
Evaluates expression once,
assigns target based on matching choice,
uses 'others' as default fallback.
Full Transcript
This visual execution trace shows how a VHDL selected assignment works. The select expression 'sel' is checked against each choice. When a match is found, the corresponding value is assigned to 'out'. If no explicit match occurs, the 'others' choice assigns a default value. The execution table steps through different sel values and shows the assigned output. The variable tracker records how 'sel' and 'out' change at each step. Key moments clarify why 'others' is important and how matching is unique. The quiz tests understanding of matching and assignment. The snapshot summarizes syntax and behavior for quick reference.

Practice

(1/5)
1. What is the main purpose of a with-select statement in VHDL?
easy
A. To create a loop that repeats a set of statements
B. To declare a new signal in the architecture
C. To assign a value to a signal based on the value of another signal
D. To define a new data type

Solution

  1. Step 1: Understand the role of with-select

    The with-select statement chooses a value for a signal depending on another signal's value.
  2. Step 2: Compare with other options

    Loops, declarations, and data types are unrelated to with-select.
  3. Final Answer:

    To assign a value to a signal based on the value of another signal -> Option C
  4. Quick Check:

    Selected assignment = conditional signal assignment [OK]
Hint: Remember: with-select picks signal values based on another signal [OK]
Common Mistakes:
  • Confusing with loops or process statements
  • Thinking it declares signals
  • Mixing with data type definitions
2. Which of the following is the correct syntax for a with-select assignment in VHDL?
easy
A. with sel select out = "00" when "00", "01" when "01", others => "11";
B. with sel select out <= "00" when "00", "01" when "01", others => "11";
C. with sel select out <= "00" when => "00", "01" when => "01", others => "11";
D. with sel select out <= "00" when "00" "01" when "01", others => "11";

Solution

  1. Step 1: Check the syntax format

    The correct syntax uses commas between choices and when others => for default.
  2. Step 2: Identify the correct arrow symbol

    The assignment uses <= and the choices use => after when.
  3. Final Answer:

    with sel select out <= "00" when "00", "01" when "01", others => "11"; -> Option B
  4. Quick Check:

    Correct syntax uses commas and 'others =>' [OK]
Hint: Look for commas between choices and 'others =>' for default [OK]
Common Mistakes:
  • Using wrong arrow symbols
  • Missing commas between choices
  • Omitting 'others =>' clause
3. Given the following VHDL code:
with sel select
  out <= "00" when "00",
         "01" when "01",
         "10" when "10",
         others => "11";

sel = "10";

What will be the value of out?
medium
A. "10"
B. "01"
C. "00"
D. "11"

Solution

  1. Step 1: Match sel value with choices

    The value of sel is "10", which matches the third choice.
  2. Step 2: Determine assigned value

    When sel is "10", out is assigned "10".
  3. Final Answer:

    "10" -> Option A
  4. Quick Check:

    sel = "10" means out = "10" [OK]
Hint: Match sel value exactly to get out value [OK]
Common Mistakes:
  • Choosing default 'others' instead of exact match
  • Confusing when clauses
  • Ignoring quotes around values
4. Identify the error in this with-select statement:
with sel select
  out <= "00" when "00",
         "01" when "01",
         "10" when "10";
medium
A. Missing semicolon at the end
B. Incorrect use of commas between choices
C. Wrong assignment operator used
D. Missing when others => clause

Solution

  1. Step 1: Check completeness of choices

    The with-select must cover all possible values, including unexpected ones.
  2. Step 2: Identify missing default case

    There is no when others => clause to cover unmatched values.
  3. Final Answer:

    Missing when others => clause -> Option D
  4. Quick Check:

    Always include 'when others =>' in with-select [OK]
Hint: Always add 'when others =>' to cover all cases [OK]
Common Mistakes:
  • Forgetting the default 'others' clause
  • Thinking semicolon is missing
  • Misusing commas or arrows
5. You want to assign a 2-bit output signal out based on a 2-bit input sel using with-select. The mapping is:
- "00" -> "11"
- "01" -> "10"
- "10" -> "01"
For any other value, out should be "00".

Which of the following with-select statements correctly implements this?
hard
A. with sel select out <= "11" when "00", "10" when "01", "01" when "10", others => "00";
B. with sel select out <= "00" when "00", "01" when "01", "10" when "10", others => "11";
C. with sel select out <= "11" when "00", "10" when "01", "01" when "10";
D. with sel select out <= "11" when "00", "10" when "01", "01" when "10", others => "11";

Solution

  1. Step 1: Match each sel value to correct out

    "00" maps to "11", "01" to "10", "10" to "01" as given.
  2. Step 2: Check the default others value

    For any other sel, out should be "00".
  3. Step 3: Verify options

    with sel select out <= "11" when "00", "10" when "01", "01" when "10", others => "00"; matches all mappings and default correctly.
  4. Final Answer:

    with sel select out <= "11" when "00", "10" when "01", "01" when "10", others => "00"; -> Option A
  5. Quick Check:

    Correct mapping + others = "00" [OK]
Hint: Check each mapping and default carefully in with-select [OK]
Common Mistakes:
  • Missing 'others' clause
  • Swapping output values
  • Assigning wrong default value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard