Functions and Subprograms

Uncategorized

This set of VHDL Multiple Choice Questions & Answers (MCQs) focuses on “Functions and Subprograms”.

1. Functions and subprograms are both same.
a) True
b) False

2. A function is a ________ code.
a) Concurrent
b) Sequential
c) Concurrent as well as sequential
d) Process oriented
.

3. Which of the following sequential statement can’t be used in a function?
a) WAIT
b) IF
c) CASE
d) LOOP

4. What is the correct syntax for declaration of a function?
a)

     FUNCTION function_name (parameter_list) RETURN return_type IS
     declaration_part;
     BEGIN
     sequential_statements;
     END FUNCTION;

b)

     FUNCTION function_name (parameter_list) RETURN return_type IS
     BEGIN 
     declaration_part;
     sequential_statements;
     RETURN expression;
     END FUNCTION;

c)

    FUNCTION function_name (parameter_list) RETURN return_type IS
     BEGIN
     declaration_part;
     sequential_statements;
     RETURN expression;
     END function_name;

d)

     FUNCTION function_name (parameter_list) RETURN return_type IS
     declaration_part;
     BEGIN
     sequential_statements;
     RETURN expression;
     END function_name;

5. The function is called from the ________
a) Function itself
b) Library
c) Main code
d) Package

6. The parameters used at the time of function call are called _________
a) Formal parameters
b) Actual parameters
c) Real parameters
d) Complex parameters

7. Functions are always invoked as a(n) _________
a) Constant
b) Variable
c) Signal
d) Expression

8. How many return arguments can be there in the function?
a) 1
b) 2
c) 3
d) 4

9. Which of the following can’t be the parameter of function?

SIGNAL a, b : IN STD_LOGIC
VARIABLE c : INTEGER
CONSTANT d : INTEGER

a) a
b) b
c) c
d) d

10. A function call can be a concurrent as well as a sequential statement.
a) True
b) False

11. Refer to the function defined below, a and b have respectively following data objects.

FUNCTION my_func (SIGNAL a : STD_LOGIC_VECTOR; b : STD_LOGIC) RETURN BOOLEAN IS
…..;

a) Constant, Constant
b) Constant, Signal
c) Signal, Constant
d) Signal, Signal

12. What should be the mode of signal a in the following function definition?

FUNCTION my_func (SIGNAL a : STD_LOGIC_VECTOR) RETURN INTEGER IS
…..;

a) IN
b) OUT
c) INOUT
d) BUFFER

13. Functions are called using ______ no of ________ statement(s).
a) 1, If
b) 1, Assignment
c) 2, If
d) 2, Assignment

14. Which of the following type can’t be a parameter of a function?
a) Signals
b) Constants
c) Files
d) Variables

15. A component may be declared and instantiated inside a function.
a) True
b) False

16. What is the use of resolution functions?
a) Return the value of a signal with multiple drivers
b) Resolve value of a constant with multiple drivers
c) Convert one data type into another
d) Convert one data object into another

17. It is not possible to use multiple driver signals without a resolution function.
a) True
b) False

18. A resolution function is invoked when ________
a) The signal is assigned multiple values
b) All the drivers has changed their value for once at least
c) Any of the driver changes its value
d) The signal is assigned a second value

19. How many parameters are there in a resolution function?
a) 3
b) 2
c) 0
d) 1

20. What would be the length of array used as a parameter to the resolution function which resolves the value of a signal having 2 drivers?
a) 1
b) 2
c) 3
d) Infinite

21. In VHDL it is not possible to use recursive functions.
a) True
b) False

22. Apart from using WAIT statements, which of the following is not possible in functions?
a) Variable assignment
b) Return statement
c) Variable declaration
d) Signal assignment

23. Conversion functions are used to _________
a) Resolve value of a signal with multiple drivers
b) Convert one data type into another
c) Convert one data object into another
d) Resolve value of a constant with multiple drivers

24. The variables declared inside a function retain their values between two function calls.
a) True
b) False

25. The minimum number of parameters that must be there in a function is ___________
a) 0
b) 1
c) 2
d) 3

26. Which of the following is not the legal name of a function?
a) abc
b) +
c) then
d) my_func

27. In the following code, which of the lines corresponds to the function call and function definition?

L1 : ARCHITECTURE adder OF adder IS
L2 : BEGIN
L3 : x <= sum ( SIGNAL a : STD_LOGIC; SIGNAL b : STD_LOGIC);
L4 : END adder;
L5 : FUNCTION sum ( SIGNAL a : STD_LOGIC; SIGNAL b : STD_LOGIC) RETURN STD_LOGIC IS
L6 : VARIABLE c : INTEGER;
L7 : BEGIN
L8 : c<= a OR b;
L9 : RETURN c;
L10 : END sum;

a) L5, L3
b) L5, L9
c) L3, L7
d) L3, L5

28. What is the ease provided by using functions?
a) Easy debugging
b) Easy reading
c) Easy calling
d) Easy implementation

29. If a function has an operator sign as its name, then what will be the purpose of that function?
a) Conversion
b) Overloading
c) Resolution
d) Define the data type

30. What is the alternative for specifying the vector size in the function?
a) Not using arrays
b) Defining every single element differently
c) Defining a subtype
d) Using bit vector

Leave a Reply

Your email address will not be published. Required fields are marked *