VHDL Questions and Answers Part-7

1. How the keyword “TYPE” is used?
a) TYPE datatype_name IS type_from_predefined_datatypes;
b) TYPE datatype_name IS datatype_range;
c) TYPE datatype_range IS datatype_name;
d) USE TYPE datatype_range IS datatype_name;

Answer: b
Explanation: The keyword TYPE is used to define new data type if any user wants to define for its own. The syntax for keyword is- TYPE datatype_name IS datatype_range. So, the new data type can have the values defined in range section of the declaration.

2. Which of the following is a wrong declaration for a new data type?
a) TYPE my_logic IS RANGE 0 to 100;
b) TYPE my_logic IS (‘0’, ‘1’, ‘2’);
c) TYPE my_logic IS ARRAY (0 TO 3) OF BIT;
d) TYPE my_logic IS <0 TO 20 >

Answer: d
Explanation: TYPE can be used in three forms as shown above. For defining range, there are two methods as illustrated in option TYPE my_logic IS RANGE 0 to 100; and option TYPE my_logic IS (‘0’, ‘1’, ‘2’);. If we want to define a user defined array then the sytanx like option TYPE my_logic IS ARRAY (0 TO 3) OF BIT; follows. But, we can’t define range by using <> sign.

3. One can’t define an array without any constraints in VHDL.
a) True
b) False

Answer: b
Explanation: We can define an array without any constraints in VHDL. When there are no constraints in array then it can have any number of elements. For example, TYPE my_type IS ARRAY (RANGE <>) OF BIT; this declaration defines an array of BIT data type without any constraint on the number of elements in the array.

4. A SUBTYPE can be defined as _________
a) A TYPE under a TYPE (nested)
b) A type of INTEGER datatype
c) A TYPE with some constraint
d) A TYPE without any constraint

Answer: c
Explanation: A SUBTYPE is a TYPE with some constraints. TYPE can be predefined data type and it can also be any user defined data type. But if SUBTYPE is derived from user defined datatype, then we first have to declare the type along with its range and then subtype can be defined.

5. Which of the following is the correct syntax for declaring a SUBTYPE?
a) TYPE type_name IS type_range AND SUBTYPE subtype_name IS subtype_range
b) SUBTYPE subtype_name IS subtype_range TYPE type_name
c) SUBTYPE subtype_name TYPE type_name IS subtype_range
d) SUBTYPE subtype_name IS TYPE subtype_range

Answer: d
Explanation: The correct way to define a SUBTYPE is the syntax shown in option d. For example, if we want to define a SUBTYPE of STD_LOGIC with 3 values only like X, 0 and 1. We can define it as SUBTYPE my _ subtype IS STD_LOGIC RANGE ‘X’ TO ‘1’.

6. User can define its own integer data type.
a) True
b) False

Answer: a
Explanation: In VHDL, user can define either its own integer type or enumerated type. User defined integer type must always be a subset of predefined datatype. User can define the integer with some desired range. For example, we can define any integer named as my_integer with range 0 to 32 as given: TYPE my_integer IS RANGE 0 TO 32; in this way, one can define a subset of integer.

7. One can perform basic operations between different data types.
a) True
b) False

Answer: b
Explanation: VHDL is a strongly typed language i.e. it has very strict rules about predefined and user defined data types. So, we can’t perform any operation between data of different types. Although, it is possible to perform operation between two data types with same base.

8. If we are using conv_integer(p) function, then which of the following cannot be the type of parameter ‘p’?
a) INTEGER
b) STD_ULOGIC
c) STD_LOGIC VECTOR
d) SIGNED

Answer: c
Explanation: The function conv_integer(p) is used to convert the parameter ‘p’ of any type excluding STD_LOGIC_VECTOR into the integer type. This function can covert INTEGER, SIGNED, UNSIGNED, STD_ULOGIC types into integer type. After converting only, we can use ‘p’ as INTEGER type.

9. In the function conv_unsigned(p, b), what does p and b refers to?
a) p is the data object to be converted and b is the base of that data object
b) p is the data object to be converted amd b is the bits needed in converted variable
c) p is the parameter to be converted and b is the bits of same parameter
d) p is the type of data to be converted and b is the type of data into which p should be converted

Answer: b
Explanation: The function conv_unsigned is used to convert different data types in UNSIGNED type. Two arguments are used in this function which are p and b. p is the data object which we need to convert and b represents the no of bits in UNSIGNED type. So, conv_unsigned(p,b) converts the parameter ‘p’ of INTEGER, SIGNED, UNSIGNED, STD_ULGOIC into UNSIGNED type of size ‘b’ bits.

10. Which of the following is the correct syntax to convert INTEGER ‘p’ into SIGNED number of ‘b’ bits?
a) conv_integer_signed(p,b);
b) conv_signed_integer(p,b);
c) conv_signed(p,b);
d) conv_signed_p(b);

Answer: c
Explanation: To convert INTEGER, SIGNED, UNSIGNED and STD_ULOGIC types into SIGNED type, the function conv_signed is used. The correct way to use this function is :- conv_signed(p,b) where p is the object to be converted and b is the number of bits in SIGNED type.