Appendix A

Operator Precedence

If no parentheses are used to separate operands then Verilog uses the following rules of precedence. It is normally a good idea to use parentheses to make expressions readable. Below is a list of all operators provided by Verilog and their precedence rules.

List of Operators provided by Verilog

        -----------------------------------------------------------
        |   Operator    | Operator |    Operation     | Number of |
        |    Type       |  Symbol  |                  | Operands  |
        -----------------------------------------------------------
        | Arithmetic    |    *     | multiply         |    two    |
        |               |    /     | divide           |    two    |
        |               |    +     | add              |    two    |
        |               |    -     | subtract         |    two    |
        |               |    %     | modulus          |    two    |
        -----------------------------------------------------------
        | Logical       |    !     | logical negation |    one    |
        |               |    &&    | logical and      |    two    |
        |               |    ||    | logical or       |    two    |
        -----------------------------------------------------------
        | Relational    |    >     | greater than     |    two    |
        |               |    <     | less than        |    two    |
        |               |    >=    | greater or equal |    two    |
        |               |    <=    | less or equal    |    two    |
        -----------------------------------------------------------
        | Equality      |    ==    | equality         |    two    |
        |               |    !=    | inequality       |    two    |
        |               |    ===   | case equality    |    two    |
        |               |    !==   | case inequality  |    two    |
        -----------------------------------------------------------
        | Bitwise       |    ~     | bitwise negation |    one    |
        |               |    &     | bitwise and      |    two    |
        |               |    |     | bitwise or       |    two    |
        |               |    ^     | bitwise xor      |    two    |
        |               |  ^~or~^  | bitwise xnor     |    two    |
        -----------------------------------------------------------
        | Reduction     |    &     | reduction and    |    one    |
        |               |    ~&    | reduction nand   |    one    |
        |               |    |     | reduction or     |    one    |
        |               |    ~|    | reduction nor    |    one    |
        |               |    ^     | reduction xor    |    one    |
        |               |  ^~or^~  | reduction xnor   |    one    |
        -----------------------------------------------------------
        | Shift         |    >>    | right shift      |    two    |
        |               |    <<    | left shift       |    two    |
        ----------------------------------------------- -----------
        | Concatenation |    {}    | concatenation    |    any    |
        -----------------------------------------------------------
        | Replication   |    {{}}  | replication      |    any    |
        -----------------------------------------------------------
        | Conditional   |    ?:    | conditional      |    three  |
        -----------------------------------------------------------

Operator Precedence

        -----------------------------------
        | Operator           | Precedence |
        -----------------------------------
        | + - ! ~ (unary)    |  highest   |
        | * / %              |            |
        | + - (binary)       |            |
        | << >>              |            |
        | < <= > >=          |            |
        | == != === !==      |            |
        | & ~&               |            |
        | ^ ^~               |            |
        | | ~|               |            |
        | &&                 |            |
        | ||                 |            |
        | ?: (conditional)   |  lowest    |
        -----------------------------------


next contents