This set of VHDL Multiple Choice Questions & Answers (MCQs) on “Procedures – 1”.
1. Procedures are invoked as _________
a) Statements
b) Expressions
c) Values
d) Assignments
Answer: a
Clarification: Unlike functions, procedures are invoked as a statement. Functions are always invoked as expressions as a part of the assignment statement but procedures are directly called as statements only. No assignment operator is needed.
2. Procedures are useful when _________
a) Functions are not synthesizable
b) Signals are needed to be declare
c) Multiple values are needed as a result
d) Architecture can’t contain some statement
Answer: c
Clarification: Procedures usually returns many values, which is not possible with the case of function. So, procedures are useful when there are multiple results coming from the procedure. Note that procedure can return single value as well.
3. Which of the following is correct syntax for procedure body?
a)
PROCEDURE procedure_name (parameter_list) IS BEGIN declarations; sequential_statements; END PROCEDURE;
b)
PROCEDURE procedure_name (parameter_list) IS declarations; BEGIN sequential_statements; END procedure_name;
c)
PROCEDURE procedure_name (parameter_list) IS declarations; BEGIN sequential_statements; concureent_statements; END PROCEDURE;
d)
PROCEDURE procedure_name (parameter_list) IS declarations; BEGIN sequential_statements; concurrent_statements; END procedure_name;
View Answer
Answer: b
Clarification: The procedure definition is very similar to the function definition. It starts with the keyword PROCEDURE followed by the name of procedure and then the parameter list. Then local declarations are made within the procedure body, which are separated from the statements part by the keyword begin. Then the procedure body is ended by the keyword END followed by name of procedure.
4. Procedure doesn’t have a return type.
a) True
b) False
Answer: a
Clarification: Functions always have a return type which specifies the type of value which is returned by the function. But, procedures return multiple values; therefore, it is not possible to use a single return type. So, There is no return type for a procedure.
5. Which of the following could be the objects in the parameter list of a procedure?
a) CONSTANTS, VARIABLES
b) VARIABLES, SIGNALS
c) CONSTANTS, SIGNALS
d) CONSTANT, SIGNALS, VARIABLES
Answer: d
Clarification: A procedure may have any of three objects in its parameter list. A SIGNAL, CONSTANT as well as a VARIABLE can be used as a parameter to a procedure. In functions, only signals and constants can be parameters.
6. A procedure can’t contain a _______ statement.
a) WAIT
b) IF
c) RETURN
d) CASE
Answer: c
Clarification: A procedure, unlike functions, may contain WAIT statement but it doesn’t include any return statement. The assignments made in the procedure are considered as the values which are needed to be returned to the main code.
7. The parameter of a procedure can have any of the three modes.
a) True
b) False
Answer: a
Clarification: A procedure can have any number of IN, OUT or INOUT parameters which can be signals, constants or variables. There is no restriction on the mode of the signal It may be any of the three modes which are IN, OUT or INOUT.
8. Which of the following is the default class of any parameter with its mode as IN?
a) SIGNAL
b) CONSTANT
c) VARIABLE
d) SIGNAL or VARIABLE
Answer: b
Clarification: The default class for any IN mode parameter is CONSTANT. It means that if no mode is specified the parameters of mode IN are interpreted as class CONSTANT.
9. Which of the following is the default mode of a parameter of procedure?
a) IN
b) OUT
c) INOUT
d) IN or INOUT
Answer: a
Clarification: If no mode is specified in the front of a parameter, then it is considered as an input signal or of a mode IN. So, The default mode for a parameter of a procedure is IN mode which is similar to the functions.
10. It is given that the mode of a parameter is OUT mode but its class is not specified by the user. To which class does it belong?
a) INTEGER
b) CONSTANT
c) VARIABLE
d) SIGNAL
Answer: c
Clarification: The CONSTANT is the default class for the parameters of mode IN only. For other parameters that have their mode either as OUT or as INOUT the default class is considered as VARIABLE class.