Verilog 基礎(chǔ)語法

2022-05-16 13:51 更新

格式

Verilog 是區(qū)分大小寫的。

格式自由,可以在一行內(nèi)編寫,也可跨多行編寫。

每個(gè)語句必須以分號(hào)為結(jié)束符。空白符(換行、制表、空格)都沒有實(shí)際的意義,在編譯階段可忽略。例如下面兩中編程方式都是等效的。

不換行(不推薦)

wire [1:0]  results ;assign results = (a == 1'b0) ? 2'b01 : (b==1'b0) ? 2'b10 : 2'b11 ;

換行(推薦)

wire [1:0]  results ;
assign      results = (a == 1'b0) ? 2'b01 :
            (b==1'b0) ? 2'b10 :
                2'b11 ;

注釋

Verilog 中有 2 種注釋方式:

用 ?//? 進(jìn)行單行注釋:

reg [3:0] counter ;  // A definition of counter register

用 ?/*? 與 ?*/? 進(jìn)行跨行注釋:

wire [11:0]  addr ;
/* 
Next are notes with multiple lines.
Codes here cannot be compiled.
*/
assign   addr = 12'b0 ;

標(biāo)識(shí)符與關(guān)鍵字

標(biāo)識(shí)符(identifier)可以是任意一組字母、數(shù)字、?$? 符號(hào)和 ?_?(下劃線)符號(hào)的合,但標(biāo)識(shí)符的第一個(gè)字符必須是字母或者下劃線,不能以數(shù)字或者美元符開始。

另外,標(biāo)識(shí)符是區(qū)分大小寫的。

關(guān)鍵字是 Verilog 中預(yù)留的用于定義語言結(jié)構(gòu)的特殊標(biāo)識(shí)符。

Verilog 中關(guān)鍵字全部為小寫。

reg [3:0] counter ; //reg 為關(guān)鍵字, counter 為標(biāo)識(shí)符
input clk; //input 為關(guān)鍵字,clk 為標(biāo)識(shí)符
input CLK; //CLK 與 clk是 2 個(gè)不同的標(biāo)識(shí)符


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)