2.1 Verilog Basic Syntax
Classification Verilog Tutorial
Format
Verilog is case-sensitive.
The format is free, you can write in one line or across multiple lines.
Each statement must end with a semicolon. White spaces (line breaks, tabs, spaces) have no actual meaning and can be ignored at the compilation stage. For example, the following two programming methods are equivalent.
No Line Break (Not Recommended)
Example
wire [1:0] results; assign results = (a == 1'b0) ? 2'b01 : (b == 1'b0) ? 2'b10 : 2'b11;
Line Break (Recommended)
Example
wire [1:0] results;
assign results = (a == 1'b0) ? 2'b01 :
(b == 1'b0) ? 2'b10 :
2'b11;
Comments
There are 2 types of comments in Verilog:
Use //
for single-line comments:
reg [3:0] counter; // A definition of counter register
Use /*
and */
for multi-line comments:
wire [11:0] addr;
/*
Next are notes with multiple lines.
Codes here cannot be compiled.
*/
assign addr = 12'b0;
Identifiers and Keywords
Identifiers can be any combination of letters, numbers, $
sign, and _
(underscore), but the first character of an identifier must be a letter or underscore, not starting with a number or dollar sign.
Also, identifiers are case-sensitive.
Keywords are special identifiers reserved in Verilog to define the language structure.
All keywords in Verilog are in lowercase.
Example
reg [3:0] counter; // 'reg' is a keyword, 'counter' is an identifier
input clk; // 'input' is a keyword, 'clk' is an identifier
input CLK; // 'CLK' is a different identifier from 'clk'
2.1 Verilog Basic Syntax
[7.3 Ver