# VHDL Questions and Answers – Operators – 1

This set of VHDL Multiple Choice Questions & Answers (MCQs) focuses on “Operators – 1”.

1. Which of the following is not an assignment operator?
a) <=
b) :=
c) =>
d) =

Explanation: Assignment operators are used to assign some value to a data object. <= operator is used to assign values to a SIGNAL. := operator is used to assign values to VARIABLE, CONSTANTS and GENERICS; this operator is also used for assigning initial values. Another assignment operator is =>, used to assign values to individual vector elements or others.

2. A VARIABLE y is declared of STD_LOGIC_VECTOR type of 4 bits, if you want to assign 1001 to y, then what is the write assignment statement?
a) y <= “1001”
b) y := “1001”
c) y <= ‘1’, ‘0’, ‘0’, ‘1’
d) y => “1001”

Explanation: To assign values to any variable, the := operator is used. Since, y is a VARIABLE STD_LOGIC_VECTOR type, we can only use := operator and not <= operator. => can be used, but while assigning individual elements of a vector.

3. Refer to the VHDL code given below, which is the legal assignment statement?

```SIGNAL x: STD_LOGIC;
SIGNAL y: STD_LOGIC_VECTOR(3 DOWNTO 0);```

a) y <= (1 => ‘1’, OTHERS => ’0’);
b) y := “0100”;
c) y => “0100”;
d) y => x;

Explanation: To assign a value to a SIGNAL, either <= or => can be used only. But, if we want to use =>, then values need to be assigned to individual elements. => is used with OTHERS. Y<= (1<=’1’, OTHERS =>’0’) means that the value assigned to y is 0100.
Note: Join free Sanfoundry classes at Telegram or Youtube

4. Which of the following logical operator has the highest precedence?
a) NAND
b) NOR
c) NOT
d) EXOR

Explanation: NOT is the logical operator which has highest precedence. If there are more than one logical operator in the same statement, then NOT will be given highest preference. If there is any () in the statement then first preference will be given to () and then to NOT operator.

5. In the following statements, y and z are equivalent to________

```y <= NOT a AND b;
z <= NOT (a AND b);```

a) y <= a’+b’ and z <= (a.b)’
b) y <= (a+b)’ and z <= a’+b’
c) y <= a’+b and z <= a’+b’
d) y <= a+b’ and z <= a.b

Explanation: As discussed above, NOT will be given highest preference. So, y becomes ((NOT a)AND b) which is a’+b. similarly, in z first of all () will be solved i.e.(a AND b)’ which is (a.b)’. By, De Morgan’s law, (a.b)’ = a’+b’. Therefore, y = a’+b and z = a’+b’.

6. Which of the following VHDL statement is equivalent to NAND operation, if y, a and b are SIGNALS?
a) y <= NOT a AND b
b) y <= NOT a OR NOT b
c) y <<= NOT a AND NOT b
d) y <<= NOT (a OR b)

Explanation: Logic NAND operation is (a.b)’ which is equivalent to a’ + b’ by using De Morgan’s law. NOT a AND b is equivalent to (a’.b). NOT a AND NOT b is equivalent to (a’.b’). Similarly, NOT (a OR b) is (a+b)’.

7. ______ operator is unary as well as binary operator.
a) –
b) *
c) /
d) **

Explanation: Unary operator is the one which needs only one operand and Binary operator needs two operands. ‘–’ is the only operator which can be used with one as well as two operands. When used with single operand, the result is negative of the same number and similarly, when used with two operands then the result is difference of two operands.

8. The operator ‘&’ is called the_____ operator.
a) Logical AND operator
b) Bitwise AND operator
d) Concatenation operator

Explanation: ‘&’ is called the concatenation operator and is a binary operator. It needs two operands and both of them must be arrays. It combines two arrays and produces one array of the size equal to the sum of sizes of two arrays.

9. What is the type of result of MOD operator?
a) Numeric
b) Integer
c) Array
d) Bit

Explanation: The MOD operator is called the modulo operator which gives the remainder of the division of two integers and hence the result is of integer type. For example, y <= a MOD b; will return the value of remainder when a is divided by b. suppose a= 12 and b= 5 then the value of y will be 2.

10. The operators like =, /=, <, >, >= are called _________
a) Arithmetic operators
b) Concatenation operators
c) Logical operators
d) Relational operators

Explanation: These operators are relational operators or Comparison operators since they are used to compare two operands. The = refers to equal to, /= refers to not equal to operator. Similarly,<, >, <=, >= are called less than, greater than, less than or equal to, greater than or equal to operators.

11. What is the type of result for comparison operators?
a) Boolean
b) Integer
c) Numeric
d) Array

Explanation: Comparison operators are used for the comparison of two operands and the result is of Boolean type i.e. true or false. For example, b:= “0010” < “0001”; In this statement, the value assigned to b will be FALSE, since this means 2 < 1, which is not true.

12. ABS operator is used to _________
a) Shift the operand
b) Gives absolute value for the operand
c) Give the result as nearest integer
d) To synthesize the result

Explanation: ABS operator is a unary operator which returns the absolute value. We can use this operator to increase the reliability of code. For example, we need to use π, then the value of the same is 22/7 or 3.14. In VHDL, if we use following statements: pi = 22/7; IF(pi = 3.14) THEN WAIT; Then we might not get the result as we want. It will be unreliable. If we use ABS operator along with it, then it will be better. Like, IF(abs(pi)=3.14) THEN WAIT; this will give the desired result.

13. Which of the following is exponentiation operator?
a) ^
b) *
c) /=
d) **

Explanation: Exponentiation operator in VHDL is represented by two asterisk signs. So, ** is the exponentiation operator which comes under the category of arithmetic operators. In VHDL, a**b means a^b.

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]