Challenge - 5 Problems
If-Then-Else Mastery in VHDL
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple if-then-else in process
What is the value of
out_signal after this process runs with input_signal = '1'?VHDL
process(input_signal) begin if input_signal = '1' then out_signal <= '0'; else out_signal <= '1'; end if; end process;
Attempts:
2 left
💡 Hint
Check the condition in the if statement and what value is assigned when it is true.
✗ Incorrect
The process checks if
input_signal is '1'. Since it is, out_signal is assigned '0'.❓ Predict Output
intermediateNested if-then-else output in process
Given
input1 = '0' and input2 = '1', what is the value of out_signal after this process?VHDL
process(input1, input2) begin if input1 = '1' then out_signal <= '1'; else if input2 = '1' then out_signal <= '0'; else out_signal <= 'Z'; end if; end if; end process;
Attempts:
2 left
💡 Hint
Look at the nested if-else and the values of input1 and input2.
✗ Incorrect
Since
input1 is '0', the outer else runs. Then input2 is '1', so out_signal is assigned '0'.🔧 Debug
advancedIdentify the error in this if-then-else process
What error will this VHDL process produce?
VHDL
process(clk) begin if clk = '1' then if reset = '1' then out_signal <= '0'; else out_signal <= '1'; end if; end if; end process;
Attempts:
2 left
💡 Hint
Check each signal assignment line for proper syntax.
✗ Incorrect
The line
out_signal <= '0' is missing a semicolon at the end, causing a syntax error.🧠 Conceptual
advancedBehavior of if-then-else with multiple signals
In a process sensitive to
a and b, what will be the value of out_signal after this code runs with a = '0' and b = '0'?VHDL
process(a, b) begin if a = '1' then out_signal <= '1'; elsif b = '1' then out_signal <= '0'; else out_signal <= 'Z'; end if; end process;
Attempts:
2 left
💡 Hint
Neither
a nor b is '1', so the else branch runs.✗ Incorrect
Since both
a and b are '0', the else branch assigns 'Z' to out_signal.📝 Syntax
expertIdentify the syntax error in this if-then-else process
Which option correctly identifies the syntax error in this VHDL process?
VHDL
process(clk) begin if rising_edge(clk) then if enable = '1' then out_signal <= '1'; else out_signal <= '0'; end if; end if; end process;
Attempts:
2 left
💡 Hint
Count the if and end if statements carefully.
✗ Incorrect
There are two 'if' statements but only one 'end if;', which closes the inner if, leaving the outer if without a matching 'end if;', causing a syntax error.
