Verilog


Types

real

integer

time

reg

wire

Arithmetic operators

+

Addition

1 + 2

Unary positive, makes number positive

+2

-

Subtraction

2 - 1

Unary negative, makes number negative

*

Multiplication

2 * 3

/

Division

4 / 2

**

Indice

4 ** 2

Assignment operators

=

Equals

x = 2

Comparison operators

==

Is equal to

1 == 2

!=

Is not equal to

1 != 2

>

Greater than

1 > 2

<

Less than

1 < 2

>=

Greater than or equal to

1 >= 2

<=

Less than or equal to

1 <= 2

Bitwise operators

&

Bitwise AND

0b11001010 & 0b00100011

|

Bitwise OR

0b11001010 | 0b00100011

^

Bitwise XOR

0b11001010 ^ 0b00100011

~

Bitwise NOT

~0b00100011

~&

Bitwise NAND

~|

Bitwise NOR

Shift operators

<<

Arithmetic shift left (shifts all the bits one space to the left, essentially multiplying it by 2)

0b11001010 << 2

>>

Logical shift right (shifts all the bits one space to the right, essentially dividing it by 2)

0b11001010 >> 2

Logical operators

&&

AND operator

1 && 0

||

OR operator

1 || 0

!

NOT operator

!1

Miscellaneous operators

,

Links related expressions together

[]

Denotes an object is an array during declaration, also holds the array's size, unless being initialised

int numbers[4];

References a array's index

numbers[3]

()

Denotes parameters of a module

Denotes the condition of a block

{}

Concatenates strings

void foo() {
}

Initialises an array

int numbers[] = {0, 1, 2, 3};

:

Used for cases

case 1:

""

Declares a string

"Hello world!"

''

Declares a string

'Hello world!'

;

Declares end of a line of code

break;

...

Declares multiple arguments

double average(int number, ...) {

s't

Numerical prefix where "s" denotes size of data in bits and "t" denotes the type of digit system

Key word

module

input

output

begin

Begins a statement

end

Ends a statement

default

Default case in a case statement

initial

Block of code executed at the initiation of execution and then never again

always

repeat

always

if

Used for declaring if statements

while

Used for declaring while loops

for

Used for declaring for loops

else

Used for declaring else statements

continue

Used to tell compiler to complete the next iteration of a loop

break

Used to tell compiler to end the loop

Commenting

//

Used to tell compiler the rest of this line is not to be compiled

/*

Opens a multi line comment

*/

Closes a multi line comment