Operators in VHDL

In this article, working of operators in VHDL are discussed in detail. The main purpose of any code is to implement some kind of logic. Operators help us to build that logic.

The predefined operators in the language are classified into the following five categories:

  1. Logical operators
  2. Relational operators
  3. Shift operators
  4. Adding operators
  5. Multiplying operators
  6. Miscellaneous operators

The operators have increasing priority that is logical operators have lowest priority and Miscellaneous operators have highest priority.

Operators in the same category have the same priority and evaluation is done left to right. Parentheses can be used to override the left to right evaluation.

Logical Operators in VHDL

The logical operators in VHDL are

and

Logical AND

or

Logical OR

nand

Logical NAND

nor

Logical NOR

xor

Logical Exclusive OR

xnor

Logical Exclusive of NOR

not

Logical NOT

Logical operators perform logic operations between

  1. Bit and Boolean data and
  2. One dimensional logical arrays of bit and Boolean data.

Logical AND

Performs logical AND operation with a logical array or Boolean. The and keyword is used to specify an ANDing operation between the two elements.

Syntax:

<logical_array_variable> <= <logical_array> and <logical _array>;

<boolean_variable> <= <boolean> and <boolean>;

Example:

Y<= A and B;

Logical OR

Performs logical OR operation with a logical array or Boolean. The or keyword is used to specify an ORing operation between the two elements.

Syntax:

<logical_array_storage> <= <logical_array> or <logical _array>;

<boolean_storage> <= <boolean> or <boolean>;

Example:

Y<= A or B;

Logical NAND

Performs logical NAND operation with a logical array or Boolean. The nand keyword is used to specify a NAND between the two elements.

Syntax:

<logical_array_storage> <= <logical_array> nand <logical _array>;

<boolean_storage> <= <boolean> nand <boolean>;

Example:

Y<= A nand B;

Logical NOR

Performs logical NOR operation with a logical array or boolean. The nor keyword is used to specify a NOR between the two elements.

Syntax:

<logical_array_storage> <= <logical_array> nor <logical _array>;

<boolean_storage> <= <boolean> nor <boolean>;

Example:

Y<= A nor B;

Logical XOR

Performs logical exclusive OR operation with a logical array or Boolean. The xor keyword is used to specify an XOR between the two elements.

Syntax:

<logical_array_storage> <= <logical_array> xor <logical _array>;

<boolean_storage> <= <boolean> xor <boolean>;

Example:

Y<= A xor B;

Logical XNOR

Performs logical exclusive NOR operation with a logical array or Boolean. The xnor keyword is used to specify an XNOR between the two elements.

Syntax:

<logical_array_storage> <= <logical_array> xnor <logical _array>;

<boolean_storage> <= <boolean> xnor <boolean>;

Example:

Y<= A xnor B;

Logical NOT

Performs logical NOT (complement) operation with a logical array or Boolean. The not keyword is used before an element to specify a complement of the element.

Logic or boolean data type (TRUE or FALSE) is used for this operation, the result is of the same data type and is a complement of the data provided. The not operator has the same priority as that of miscellaneous operator.

Syntax:

not <logic or boolean>;

Example:

Y<= NOT A;

The result of a logical operation has the same type as its operands.

Y<= A and B or C;

The above statement is illegal; hence the parenthesis is use to avoid this problem.

Relational Operators

The relational operators allow checking relation between operands, i.e. to state whether they are equal, not equal or are ordered in a way defined by operator. Both operands must be of the same type, and the result received is always of the Boolean type.

The relational operators in VHDL are

=

Equality

/=

Inequality

<

Ordering “less than”

<=

Ordering “less than or equal”

>

Ordering “greater than”

>=

Ordering “greater than or equal”


The equality (=) and inequality (/=) operators are predefined for all data types except the file type. The equality operator returns the value TRUE only when both operands have the same values, and FALSE when the values are different. The inequality operator returns the value TRUE when the operators are different and FALSE when they are equal.

For other four relational operators (<, <=, >, and >=) the operands must be of a scalar type or one-dimensional array types. These operators return the TRUE logical value only when the condition in the given relation is met, otherwise the FALSE value is returned.

Shift Operators

The shift operators in VHDL are

sll

shift left logical

srl

shift right logical

sla

shift left arithmetic

sra

shift right arithmetic

rol

rotate left

ror

rotate right

Each of the operators takes an array of bit or boolean as the left operand and integer value as right operand and performs the specifies operation.

Adding Operators

The adding operators in VHDL are

+

Addition

Subtraction

&

Concatenation

Addition

A simple addition operator. A ‘+’ sign is used to specify the addition between two numeric values. The <numeric> is any numeric value given for addition, result is a summation of both the numeric values.

Syntax:

<numeric> + <numeric>;

Subtraction

A simple subtraction operator. A ‘-‘ sign is used to specify the subtraction between two numeric values. The <numeric> is any numeric value given for subtraction, result is the difference for both the numeric values.

Syntax:

<numeric> – <numeric>;

Concatenation

An ‘&’ is used before the <array or element> to specify a concatenation operator. The <array or element> value is used for the operation, and the yield is a concatenation (joining) of the arrays or elements value. The result is always an array element.

Syntax:

<array or element> & <array or element>;

Example:

‘0’ & ‘1’ — Result is “01”

‘E’&’F’&’Y’ — Result is “EFY”

Multiplying Operators

The multiplying operators in VHDL are

*

Multiplication

/

Division

mod

Modulus

rem

Remainder

Multiplication

A ‘*’ sign is used to specify the multiplication between two numeric values. The <numeric> is any numeric value given for subtraction, the yield is the multiplication of both the numeric values.

Syntax:

<numeric> * <numeric>;

Division

A ‘/’ sign is used to specify the division between two numeric values. The <numeric> is any numeric value given for division, and the yield is the quotient after the division of both the numeric values.

Syntax:

<numeric> / <numeric>;

Modulus

A ‘mod’ is used to specify the modulo operator. <integer> values are used for the operation, and the result is the modulo for the given integer values. It gives the remainder of the division operation.

A mod B = A – B*N — N some integer

Syntax:

<integer> mod <integer>;

Example:

7 mod 4 — A mod B = A – B*N where N some integer

— Result =3 (i.e. 7-4*1 =3)

7 mod (-4) — Result= -1 (i.e. 7- (-4*-2)

Remainder

A ‘rem’ is used to specify the remainder operator. The <integer> values are used for the operation, and the yield is the remainder for the given integer values.

Syntax:

<integer> rem <integer>;

Example:

7 rem 4 — A rem B = A – (A/B)*B

— Result =3 (i.e. 7-(7/4)*4 =3)

(-7) rem (-4) — Result= -3 (i.e. (-7)- (-7/-4)*(-4)

Miscellaneous Operators

The miscellaneous operators in VHDL are

**

Exponentiation

abs

Absolute value

These operators are extremely significant for advanced mathematics in VHDL.

Exponentiation

A ‘**’ sign is used to specify the use of exponentiation. The left operand to be <numeric> (integer or real type) and for the right operand (i.e. exponent) to be of integer type only. The result is the exponentiation of the numeric values.

Syntax:

<numeric> ** <integer>;

Example:

2**8 — Result = 28 = 256

3.5**3 — Result = 3.53 = 42.875

The ‘not’ logical operator has the same priority as of these two operators.

Absolute value

‘abs’ is used to specify the absolute value. The <numeric> is any numeric value given for the operation, and the yield is the absolute value (modulus) for the given numeric value.

Syntax:

abs <numeric>;

Example:

abs(-2) — Result = 2

Special Arithmetic Operators

Special arithmetic operators are used when special conditions arise. These operators include,

  • Unary plus +
  • Unary minus –

Unary plus

An ‘+’ is used before the <numeric> to specify a unary plus operator. The <numeric> value is used for the operation, and the result is a numeric value. When this operator is used, the numeric value returns unchanged.

Syntax:

+ <numeric>;

Unary minus

An ‘-‘ is used before the <numeric> to specify a unary minus operator. The <numeric> value is used for the operation, and the result is a numeric value. When this operator is used, the numeric value returns with the negative sign.

Syntax:

– <numeric>;

Remember to use this operator with parenthesis in the case of any other operator preceding it. For example, 5 * -4 is invalid. It should be 5 * (-4).

Have a Look

Logical operators →and|or|nand|nor|xor|xnor|not

Relational operators →=|/=|<|<=|>|>=

Shift operator →sll|srl|sla|sra|rol|ror

adding operators →+||&

multiplying operators →*|/|mod|rem

miscellaneous operators →**|abs

Recent posts

1 thought on “Operators in VHDL”

  1. A person neϲеssаrily lеnd a hand to make severely articles I might state.

    Tһis is tһe very first time I frequented your ԝeb page and
    up to now? I surprised with the research yoᥙ made
    to create this particսlar pubⅼish incredible. Magnificent job!

Comments are closed.