Selected assignment (with-select) in VHDL - Time & Space Complexity
We want to understand how the time needed to run a selected assignment using the with-select statement changes as the input size grows.
Specifically, how does the number of choices affect the time it takes to decide and assign a value?
Analyze the time complexity of the following VHDL selected assignment.
with sel select
result <= a when "00",
b when "01",
c when "10",
d when others;
This code assigns one of four signals to result based on the value of sel.
Look for repeated checks or operations that happen as the input changes.
- Primary operation: Comparing
selagainst each choice to select the right value. - How many times: Once per choice, so 4 comparisons in this example.
As the number of choices increases, the number of comparisons grows too.
| Input Size (number of choices) | Approx. Operations (comparisons) |
|---|---|
| 4 | 4 |
| 10 | 10 |
| 100 | 100 |
Pattern observation: The number of comparisons grows directly with the number of choices.
Time Complexity: O(n)
This means the time to select the correct assignment grows linearly with the number of choices.
[X] Wrong: "The selected assignment picks the right value instantly, no matter how many choices there are."
[OK] Correct: Each choice must be checked until a match is found, so more choices mean more checks and more time.
Understanding how selection statements scale helps you write efficient hardware descriptions and shows you think about performance in real designs.
"What if the selected assignment used a binary search tree structure internally? How would the time complexity change?"
Practice
with-select statement in VHDL?Solution
Step 1: Understand the role of
Thewith-selectwith-selectstatement chooses a value for a signal depending on another signal's value.Step 2: Compare with other options
Loops, declarations, and data types are unrelated towith-select.Final Answer:
To assign a value to a signal based on the value of another signal -> Option CQuick Check:
Selected assignment = conditional signal assignment [OK]
- Confusing with loops or process statements
- Thinking it declares signals
- Mixing with data type definitions
with-select assignment in VHDL?Solution
Step 1: Check the syntax format
The correct syntax uses commas between choices andwhen others =>for default.Step 2: Identify the correct arrow symbol
The assignment uses <= and the choices use => afterwhen.Final Answer:
with sel select out <= "00" when "00", "01" when "01", others => "11"; -> Option BQuick Check:
Correct syntax uses commas and 'others =>' [OK]
- Using wrong arrow symbols
- Missing commas between choices
- Omitting 'others =>' clause
with sel select
out <= "00" when "00",
"01" when "01",
"10" when "10",
others => "11";
sel = "10";What will be the value of
out?Solution
Step 1: Match
The value ofselvalue with choicesselis "10", which matches the third choice.Step 2: Determine assigned value
Whenselis "10",outis assigned "10".Final Answer:
"10" -> Option AQuick Check:
sel = "10" means out = "10" [OK]
- Choosing default 'others' instead of exact match
- Confusing when clauses
- Ignoring quotes around values
with-select statement:with sel select
out <= "00" when "00",
"01" when "01",
"10" when "10";
Solution
Step 1: Check completeness of choices
Thewith-selectmust cover all possible values, including unexpected ones.Step 2: Identify missing default case
There is nowhen others =>clause to cover unmatched values.Final Answer:
Missingwhen others =>clause -> Option DQuick Check:
Always include 'when others =>' in with-select [OK]
- Forgetting the default 'others' clause
- Thinking semicolon is missing
- Misusing commas or arrows
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?Solution
Step 1: Match each
"00" maps to "11", "01" to "10", "10" to "01" as given.selvalue to correctoutStep 2: Check the default
For any otherothersvaluesel,outshould be "00".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.Final Answer:
with sel select out <= "11" when "00", "10" when "01", "01" when "10", others => "00"; -> Option AQuick Check:
Correct mapping + others = "00" [OK]
- Missing 'others' clause
- Swapping output values
- Assigning wrong default value
Ready to prove it?
Pass the test and this pattern moves unknown
