Home / Learn Verilog / Verilog Syntax Basics: Comments, Identifiers, Keywords, Numbers

Verilog Syntax Basics: Comments, Identifiers, Keywords, Numbers

Case sensitivity, comments, names, numbers and the shape of a statement.

The gistCase sensitivity, comments, names, numbers and the shape of a statement.

The idea, explained simply

Anatomy of a number literal8'hFF8 = size in bits' h = base (b binary, o octal, d decimal, h hex)FF = digits (underscores allowed: 8'b1010_0101)
Anatomy of a number literal

The basic idea

Verilog source is plain text. Statements end with semicolons, blocks use begin and end, comments use // and /* */, and names are case sensitive.

Why this comes up

Small syntax slips cause long confusing error lists. A solid grounding saves time.

The mechanics

Identifiers start with a letter or underscore and may contain digits and $. Keywords are lowercase. Numbers can be sized: 8'hFF means 8 bits, hexadecimal, value FF.

Where it is used

  • Reading code
  • Writing clean files
  • Code reviews

Number literals

Same value, different basesVerilog: edit and run

All four notations on the first line print 255. x and z are real values in hardware simulation.

ElementExampleNotes
Line comment// textto end of line
Block comment/* text */can span lines
Identifierdata_in, _q, Q1case sensitive
Keywordmodule, assignall lowercase
Number4'b1010size, base, value
String"hello"used in $display
Operator+ - & | ^ ~see operators section
Tip:Choose one style: snake_case names, one module per file, 2 or 4 space indentation. Consistency matters more than which style.

Quick check

1. 8'hFF equals...

2. Verilog identifiers are...