0
0
VHDLprogramming~20 mins

Conditional assignment (when-else) in VHDL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
VHDL Conditional Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this VHDL conditional assignment?
Given the following VHDL code snippet, what is the value of y when a = '1' and b = '0'?
VHDL
y <= '1' when a = '1' else '0';
A'1'
B'0'
C'Z'
D'X'
Attempts:
2 left
💡 Hint
Remember, the conditional assignment sets y to '1' only if a is '1'.
Predict Output
intermediate
2:00remaining
What value does out_signal get with multiple conditions?
Consider this VHDL code:
out_signal <= '1' when sel = "00" else
              '0' when sel = "01" else
              'Z';

What is the value of out_signal when sel = "01"?
VHDL
out_signal <= '1' when sel = "00" else
              '0' when sel = "01" else
              'Z';
A'1'
B'Z'
C'0'
D'X'
Attempts:
2 left
💡 Hint
Check the order of conditions and which matches sel.
🔧 Debug
advanced
2:00remaining
Identify the error in this conditional assignment
What error will this VHDL code produce?
signal x : std_logic;
x <= '1' when a = '1' else '0' when b = '1';
VHDL
x <= '1' when a = '1' else '0' when b = '1';
ASyntax error: missing final else clause
BRuntime error: signal conflict
CNo error, code runs correctly
DType mismatch error
Attempts:
2 left
💡 Hint
Check if all possible conditions are covered with else clauses.
Predict Output
advanced
2:00remaining
What is the output of nested conditional assignments?
Given this VHDL code:
y <= '1' when (a = '1' and b = '0') else
     '0' when (a = '0' and b = '1') else
     'Z';

What is the value of y when a = '0' and b = '0'?
VHDL
y <= '1' when (a = '1' and b = '0') else
     '0' when (a = '0' and b = '1') else
     'Z';
A'1'
B'Z'
C'0'
D'X'
Attempts:
2 left
💡 Hint
Neither condition matches, so the final else applies.
🧠 Conceptual
expert
2:00remaining
How many items are in the resulting signal assignment?
Consider this VHDL conditional assignment:
signal s : std_logic_vector(3 downto 0);
s <= "0001" when cond1 else
     "0010" when cond2 else
     "0100" when cond3 else
     "1000";

How many distinct possible values can s have based on the conditions?
A1
B3
C2
D4
Attempts:
2 left
💡 Hint
Count each unique assignment including the final else.