当前位置:文档之家› Verilog基本语法

Verilog基本语法


18
整数和实数常量小结
整数的大小可以定义也可以不定义。整数表示为: 数字中(_ )忽略,便于查看 没有定义大小(size)整数缺省为32位 /*特别注意*/ 缺省数基为十进制 数基(base)和数字(16进制)中的字母无大小写之分 当数值value大于指定的大小时,截去高位。如 2'b1101表示的是 2'b01
13
3.2.1 术语及定义
1.空白符:空格、tabs及换行 2. 标志符(Identifier):Verilog中对象(如模块或信号)的名字 3.LSB:最低有效位(Lease significant bit) 4.MSB:最高有效位(Most significant bit)
14
3.2.2 空白符和注释
– include保存在文件中的全局的或经常用到的一些定义,如文本宏
– 在模块内部include一些任务(tasks),提高代码的可维护性。
26
3.2.10 文本替换`define (了解)
编译指导`define提供了一种简单的文本替换的功能 `define <macro_name> <macro_text>
多行注释,在/* */内
and and2 (b1, b, sel);
or or1 (out, a1, b1);
endmodule
15
3.2.3 Verilog采用的四值逻辑系统
‟0‟, Low, False, Logic Low, Ground,VSS, Negative Assertion
„1‟, High, True, Logic High, Power, VDD, VCC, Positive Assertion
21
3.2.6 标识符(identifiers) (重点)
标识符是用户在描述时给Verilog对象(电路模块、信号等)起的名字
标识符必须以字母(a-z, A-Z)或( _ )开头,后面可以是字母、数字、( $ )或( _ )。
最长可以是1023个字符
标识符区分大小写,sel和SEL是不同的标识符
- 2. 输入/输出说明 : input a, b, c ;
output d ;
-// 输入/输出端口信号类型声明,缺省为wire型 :
- 3. 内部信号:
wire x;
- 4. 功能定义:
assign d = a | x ;
assign x = ( b & ~c );
endmodule
6
3.1.3 逻辑功能描述
input a, b, sel; output out;
reg out;
always @( sel or a or b) if (! sel) out = a; else out = b;
endmodule
8
实例化(module instances): 1. 端口信息 2. 输入/输出说明 3. 逻辑功能描述(实例化实现功能描述)
22
有效标识符举例: shift_reg_a busa_index _bus3
无效标识符举例: 34net // 开头不是字母或“_” a*b_net // 包含了非字母或数字, “$” “_” n@238 //包含了非字母或数字, “$” “_”
Verilog区分大小写,所有Verilog关键词如module、 endmodule等都使用小写字母。
例如:
module MUX2_1 (out, a, b, sel);
output out;
input a, b, sel; wire sel_, a1, b1;
Verilog标识符
not not1 (sel_, sel); and and1 (a1, a, sel_); and and2 (b1, b, sel); or or1 (out, a1, b1); endmodule
23
3.2.7 系统任务及函数(了解)
使用方式:$<identifier> $符号指示这是系统任务和函数 系统函数有很多,如:
返回当前仿真时间$time 显示/监视信号值($display, $monitor) 停止仿真$stop 结束仿真$finish 如: $monitor($time, “a = %b, b = %h”, a, b);
编译指导`include在当前内容中插入一个文件
格式: `include “<file_name>” 如 `include "global.v"
`include "parts/count. v"
可以是相对路 径或绝对路径
`include "../../library/mux. v”
`include可用于:
在编译时<macro_text>替换<macro_name>。可提高描述的可读性。
`define not_delay #1 `define and_delay #2 `define or_delay #1 module MUX2_1 (out, a, b, sel); output out; input a, b, sel; wire sel_, a1, b1;
wire sel_, a1, b1;
/*The netlist logic selects input ”a” when sel = 0 and it selects ”b” when sel = 1. */ not not1 (sel_, sel); and and1 (a1, a, sel_);
10
练习:编写V空格中填入适当的符号 使其成为右图的Verilog 模块 :
module block1(a, b, —, —, — );
input —, —, —;
—— d, — ;
a
assign d = a | ( b & ~c) ;
b
assign e = ( b & ~c );
%h %o %d %b %c %s hex oct dec bin ACSII string
%t time
转义符
\t
\n
\\
\”
\<1-3 digit octal number>
tab 换行 反斜杠 双引号 ASCII representation of above
格式符%0d表示没有前导0的十进制数
module MUX2_1 (out, a, b, sel);
// Port declarations
单行注释
output out;
到行末结束
input sel; // control input
input b, a; /* data inputs */
格式自由
使用空白符提高可读性及代码组 织。Verilog忽略空白符除非用于 分开其它的语言标记。
c
_______
d e
11
练习答案:编写Verilog HDL模块
module block1(a, b, c, d, e ); input a, b, c; output d, e ; assign d = a | ( b & ~c) ; assign e = ( b & ~c );
endmodule
整数与实数常量例子
12
„h83a
8'b1100 0001 16'hff01 32'bz01x 3'b1010 1101
6.3 32e- 4 4.1E3
unsized decimal (zeroextended to 32 bits)
unsized hexadecimal (zeroextended to 32 bits)
可以使用一些格式符(如%b)在仿真时产生格式化输出: ”This is a normal string” ”This string has a \t tab and ends with a new line\n” ”This string formats a value: val = %b”
20
格式符
第3章 Verilog 基本语法
主要内容:
3.1 Verilog HDL基本模块说明 3.2 Verilog HDL中的词汇约定 3.3 Verilog HDL 数据类型 3.4 Verilog HDL 运算符
2
3.1 Verilog HDL基本模块说明
module是层 次化设计的基 本构件
逻辑描述放在 module内部 module能够表示:
实数常量 实数可用科学表示法或十进制表示 科学表示法表示方式: <尾数><e或E><指数>, 表示: 尾数×10指数
19
3.2.5 字符串(string)(了解)
Verilog中,字符串大多用于显示信息的命令中。(只用在测 试中!!!!)
字符串要在一行中用双引号括起来,也就是不能跨行。 字符串中可以使用一些转义(escape)符,如\t \n
当信号a或b的值发生变化时,系统任务$monitor显 示当前仿真时间,信号a值(二进制格式), 信号b值(16 进制格式)。
24
3.2.8 编译指导 (了解)
( `)符号说明一个编译指导 这些编译指导使仿真编译器进行一些特殊的操作 编译指导一直保持有效直到被覆盖或解除
25
3.2.9 文本包含`include (了解)
物理块,如IC或ASIC单元 逻辑块,如一个CPU设计的ALU部分 整个系统 每一个模块的描述从关键词module开始,有一个名称(如 SN74LS74,DFF,ALU等等),由关键词endmodule结束。
相关主题