VHDL Questions and Answers – Case Statement – 1

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
View Answer

Answer: a
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 a 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?
a) IF
b) CASE
c) WAIT
d) LOOP
View Answer

Answer: b
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 conditions is not covered by ‘cases’ in the case statement, which of the following keyword can be used to cover all those conditions?
a) ELSE
b) ELSIF
c) REMAINING
d) OTHERS
View Answer

Answer: d
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.
advertisement
advertisement

4. CASE is a sequential statement, which is similar to _________ concurrent statement.
a) Concurrent assignment
b) PORT MAP
c) WHEN
d) THEN
View Answer

Answer: c
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?
a)

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
    CASE expression IS
     WHEN choice_1 <=
     Sequential_statements;
     WHEN choice_2 <=
     Sequential_statements;
     ….
    WHEN OTHERS <=
    Sequential_statements;
    END CASE;

b)

advertisement
    CASE expression IS
     WHEN choice_1 =>
     Sequential_statements;
     WHEN choice_2 =>
     Sequential_statements;
     ….
    WHEN OTHERS =>
    Sequential_statements;
    END CASE;

c)

advertisement
    CASE expression IS
     IF choice_1 <=
     Sequential_statements;
     ELSIF choice_2 <=
     Sequential_statements;
     ….
    ELSIF OTHERS <=
    Sequential_statements;
    END CASE;

d)

    CASE expression IS
     IF choice_1 =>
     Sequential_statements;
     ELSIF choice_2 =>
     Sequential_statements;
     ….
    ELSIF OTHERS =>
    Sequential_statements;
    END CASE;
View Answer
Answer: b
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.
a) True
b) False
View Answer

Answer: b
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 &lt;= 2;
a &lt;= 4;
b &lt;= 5;
c &lt;=6;
PROCESS(a, b, c, y)
BEGIN
CASE y+1 IS
WHEN 1 =&gt;
z &lt;= a;
WHEN 2 =&gt;
z &lt;= b;
WHEN 3 =&gt;
z &lt;= c;
WHEN OTHERS =&gt;
Z &lt;= 0;
END CASE;
END PROCESS;
END example;

a) 2
b) 4
c) 5
d) 6
View Answer

Answer: d
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?
a) Boolean
b) Integer
c) Same as expression
d) No restriction on the type
View Answer

Answer: c
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 a range in the choice part of the CASE statement.
a) True
b) False
View Answer

Answer: a
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.