Verilog Study Notes Basic grammar (ii) Operator

Source: Internet
Author: User

The range of operators for Verilog HDL languages is broad and can be divided into the following types of functions:

(1) arithmetic operator +,-,*,/,%

Priority order

! ~

*  /   %

+    -

<< >>

< <= > >=

==  !==  === !===

&

^  ^~

|

&&

||

? :

Highest priority level

Lowest priority level

(2) Assignment operator =,<=

(3) Relational operators >, <,>=,<=

(4) logical operator &&, | |,!

(5) Conditional operator ? :

(6) Bitwise operator ~, |, ^,&, ^~

(7) Shift operators <<,>>

(8) concatenation operator {}

(9) Other.

1) Basic arithmetic operators: both the Plus and minus multiply are relatively simple here no longer recorded.

In the case of integer division, the result is the fractional part, which takes only the integer part, whereas the sign bit of the result of the modulo operation (%, also called the remainder operator) takes the symbol of the first operand in the modulo operator.

-10%3 Results-1 11%-3 result is 2

Note: when arithmetic operations are performed, if an operand has an indeterminate value of x, the entire result is also an indeterminate value of X.

2) Bitwise operators:

Bitwise counter ~, bitwise AND &, bitwise, OR | , bitwise XOR or ^, bitwise same OR ^~

When the data of different lengths is performed, the system automatically aligns the right end of the two numbers, and the number of operands with fewer digits will be 0 at the corresponding high position, and the two operands of the moment are bitwise operated.

3) Logical operators:

Logic and &&, logic or | |, logical NON!

where && and | | is a binocular operator whose precedence level is lower than the relational operator, and! Above arithmetic operators.

4) Relational operators

<, >, <=, >= if the relational operation is false, the return value is 0, and if the relationship of the life is true, the return value is 1. The precedence level of the relational operator is lower than the arithmetic operator.

such as: a<size-1//This is expressed in the same way as below

a< (size-1)//

Size-1<a//This expression is different from the following expression method

size-(1<a)//

5) Equality operator

= =,! =, = = =,! The = = symbol cannot have spaces between them.

"= =" and "! = "is called the logical equality operator, and the result is determined by the value of two operands. Because the operand may be x or z, the result may be x;

"= = =" and "! = = "Commonly used in the case expression of the discriminant, also known as the CAE equation operator." The result is only 0 and 1. If x and z exist in the operand, then the operand must be exactly the same as the result of 1, otherwise 0.

The difference between the logical equality operator and the case equality operator:

= = = 0 1 x Z &NBSP; = = 0 1 x Z
0 1 0 0 0 0 1 0 X X
1 0 1 0 0 1 0 1 X X
X 0 0 1 0 X X X X X
Z 0 0 0 1 Z X X X X

6) Shift operator

<<, >> A>>n where a represents the operand to be shifted, N represents the number of moves to move. Both of these shifts are used to fill the vacated slots.

If the operand already has a bit width defined, the operand changes after the shift, but its bit width is constant.

/* not understand; (Charlie Xia Third edition, p41)

4 ' b1001<<1=5 ' b10010;   4 ' b1001<<2=6 ' b100100; (moving left causes the number of bits to increase?) )

1<<6=32 ' b1000000;       4 ' b1001>>1=4 ' b0100; (Shift right does not change the number of digits?) )

4 ' b1001>>4=4 ' b0000;

*/

7) bit concatenation operator

{Some bits of signal 1, some bits of signal 2, ... Some bits of the signal n} Some of the signals are listed, separated by commas, and finally surrounded by curly braces to denote a whole signal.

A signal without a specified number of digits is not allowed in the in-place concatenation expression.

{a,b[3:0],w,3 ' b101}//equals {a,b[3],b[2],b[1],b[0],w,1b ' b0,1 ' B1}

{4{W}}//equals {w,w,w,w}

{b,{3{a,b}}}//equals {b,a,b,a,b,a,b} 3, 4 must be a constant expression.

8) Reduction operator

This is the monocular operator, and also includes the and, or, non-operations. Arithmetic rules are similar to bitwise operations, but each bit of a single operator is progressively calculated, and the result of the operation is a binary number.

c=&b; Meaning with c= ((b[0]&b[1]) &b[2]) & B[3];

Verilog Study Notes Basic grammar (ii) Operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.