This set of VHDL Multiple Choice Questions & Answers (MCQs) focuses on “Case Statement – 1”.
1. What is the problem with IF statement?
a) Overlapping of conditions
b) No default value
c) The condition can be Boolean only
d) Restriction on number of ELSE statement
Explanation: The IF statement has a priority according to which conditions are being tested. Whenever it is found to be true, all the following ELSIF statements are skipped and the END IF is executed. Sometimes, it is possible that two conditions may overlap which can cause change in output and we may not get the output as expected.
2. In which of the following statements, all the branches are equal in priority?
Explanation: Only IF and CASE statements have branches. Among which IF statement has a priority scheduled which is IF, then ELSIF sequentially and ELSE at the lowest priority. Unlike the IF statement, CASE statement has no priority. All the branches are equal in priority and all the cases are covered. Due to this, it is obvious that there must not be any overlaps.
3. In case any of the condition is not covered by ‘cases’ in the case statement, which of the following keyword can be used to cover all those conditions?
Explanation: All the possible values, which a CASE expression can take, must be covered. For covering all the remaining values, which are not specified, the keyword OTHERS is used.
4. CASE is a sequential statement, which is similar to _________ concurrent statement.
a) Concurrent assignment
b) PORT MAP
Explanation: CASE is similar to a selected signal assignment where the keyword WHEN is used along with the assignment statement. In case of sequential code, CASE can be used for the same purpose. Both CASE and WHEN uses the keyword OTHERS to handle the remaining permutations.
5. Which of the following is correct syntax for CASE statement?
CASE expression IS WHEN choice_1 <= Sequential_statements; WHEN choice_2 <= Sequential_statements; …. WHEN OTHERS <= Sequential_statements; END CASE;
CASE expression IS WHEN choice_1 => Sequential_statements; WHEN choice_2 => Sequential_statements; …. WHEN OTHERS => Sequential_statements; END CASE;
CASE expression IS IF choice_1 <= Sequential_statements; ELSIF choice_2 <= Sequential_statements; …. ELSIF OTHERS <= Sequential_statements; END CASE;
CASE expression IS IF choice_1 => Sequential_statements; ELSIF choice_2 => Sequential_statements; …. ELSIF OTHERS => Sequential_statements; END CASE;
Explanation: The CASE statement is started with the keyword CASE followed by any identifier or expression and the IS. The expression is solved to get the value and the result of expression is matched with the choices and when it is matched, the corresponding sequential statements are executed. If the value doesn’t match any of the choices, then the statements under OTHERS are executed. It may be noted that the choices are followed by the operator => but not <=.
6. The expression used in a keyword must be of a Boolean type.
Explanation: Unlike IF, it is not necessary that the expression used must give a Boolean value. It can be of any type. There is no such restriction on the type of expression used. It can be Integer, Character, Bit, Std_logic. There is no specific type of expression.
7. What will be the value of Z in the following code?
ENTITY case_1 IS Port (a, b, c, y : IN INTEGER range 0 TO 31 z : OUT INTEGER range 0 TO 31) ARCHITECTURE example OF case_1 IS BEGIN y <= 2; a <= 4; b <= 5; c <=6; PROCESS(a, b, c, y) BEGIN CASE y+1 IS WHEN 1 => z <= a; WHEN 2 => z <= b; WHEN 3 => z <= c; WHEN OTHERS => Z <= 0; END CASE; END PROCESS; END example;
Explanation: First of all the expression is solved to get an integer, which is 3. Now, integer 3 is matched with the choices and the corresponding assignment will be executed. Therefore, c will be assigned to z since the choice 3 is matched with the outcome of the expression. In this way the z will get the value of c which is 6.
8. What should be the type of choices in the CASE statement?
c) Same as expression
d) No restriction on the type
Explanation: It is necessary that the type of choices in the CASE statement is same as the type of expression in the same. For example, any expression is of type integer, and then all the choices must be of the type integer.
9. It is possible to use range in the choice part of the CASE statement.
Explanation: This is possible to use a discrete range in the choices. It is not necessary that the choice can be a single integer or character only, it can be a range too. This can be done by using TO keyword. For example, WHEN 1 TO 3 is valid in which if the expression gives the value anywhere between 1 to 3, then this part of the CASE will be executed.
Sanfoundry Global Education & Learning Series – VHDL.
To practice all areas of VHDL, here is complete set of 1000+ Multiple Choice Questions and Answers.