This set of VHDL Multiple Choice Questions & Answers (MCQs) focuses on “Functions and Subprograms – 1”.
1. Functions and subprograms are both same.
Explanation: A subprogram consists of procedures and functions. Both of them are collectively called subprograms. So, subprogram is not same as a function but a function is a part of subprogram in case of VHDL.
2. A function is a ________ code.
c) Concurrent as well as sequential
d) Process oriented
Explanation: A function is a section of sequential code. From the construction point of view, functions are very similar to the process. They employ all the sequential statements like IF, CASE etc.
3. Which of the following sequential statement can’t be used in a function?
Explanation: A function can contain any kind of sequential statement may it be IF statement, CASE statement, LOOP statement, NEXT, EXIT or NULL. The only exception is the WAIT statement. One can’t use a WAIT statement inside a function.
4. What is the correct syntax for declaration of a function?
FUNCTION function_name (parameter_list) RETURN return_type IS declaration_part; BEGIN sequential_statements; END FUNCTION;
FUNCTION function_name (parameter_list) RETURN return_type IS BEGIN declaration_part; sequential_statements; RETURN expression; END FUNCTION;
FUNCTION function_name (parameter_list) RETURN return_type IS BEGIN declaration_part; sequential_statements; RETURN expression; END function_name;
FUNCTION function_name (parameter_list) RETURN return_type IS declaration_part; BEGIN sequential_statements; RETURN expression; END function_name;
Explanation: The function is defined in the way shown in option d. The keyword FUNCTION is followed by the name of function which in turn is followed by the list of parameters in a parenthesis. After the list of parameters the return type of a function is specified followed by the declaration part of the function in which local variables can be declared. The declaration part and statement part is separated by keyword BEGIN. Then there is the RETURN statement and the function definition is end by END and function name.
5. The function is called from the ________
a) Function itself
c) Main code
Explanation: The function which is once declared is always called from the main code. Whenever a function call occurs, the control is passed to the space where the function is defined. Then, the function is executed till a RETURN statement comes, which returns the control to main code.
6. The parameters used at the time of function call are called _________
a) Formal parameters
b) Actual parameters
c) Real parameters
d) Complex parameters
Explanation: The parameters which are specified at the time of function call are called the Actual parameters whereas the parameters used at the time of function definition are called formal parameters. The values from actual parameters are copied to the formal parameters in the same order as specified.
7. Functions are always invoked as a(n) _________
Explanation: Any function having a return type is always invoked as an expression. The expression is solved in the function definition and the result is specified by the return statement which can be taken as the result of the expression itself.
8. How many return arguments can be there in the function?
Explanation: It is very important thing to note that one function can return at most one value. The expression which is used in the return statement must result in the same type as that of return type specified in the definition. The value from the return expression is then returned to the main code.
9. Which of the following can’t be the parameter of function?
SIGNAL a, b : IN STD_LOGIC VARIABLE c : INTEGER CONSTANT d : INTEGER
Explanation: The parameter of a function can either be a signal or a constant. The variable can’t be used as a parameter of a function. Any of the data types which are synthesizable are allowed to use as a type of signals or constants.
10. A function call can be a concurrent as well as sequential statement.
Explanation: The function can be called in the concurrent part of the code and it can be called in the sequential part of the code. It is not necessary that a function can be called inside a process only. However, it may be noted that function itself contains only sequential statements.
Sanfoundry Global Education & Learning Series – VHDL.
To practice all areas of VHDL, here is complete set of 1000+ Multiple Choice Questions and Answers.