
北大数字集成电路课件--verilog的符号标识.ppt
22页数字集成电路设计入门--从HDL到版图于敦山 北大微电子学系,,第五章 Verilog的词汇约定(Lexical convention),,,理解Verilog中使用的词汇约定认识语言专用标记(tokens)学习timescale,学习内容:,术语及定义,,,空白符:空格、tabs及换行Identifier: 标志符,Verilog中对象(如模块或端口)的名字Lexical: 语言中的字或词汇,或与其相关由其文法(grammar)或语法(syntax)区分LSB:最低有效位(Lease significant bit)MSB:最高有效位(Most significant bit),空白符和注释,,,module MUX2_1 (out, a, b, sel); // Port declarations output out; input sel, // control input b, /* data inputs */ a;/* The netlist logic selects input ”a” when sel = 0 and it selects ”b” when sel = 1.*/ not (sel_, sel); and (a1, a, sel_), (b1, b, sel); // What does this line do? or (out, a1, b1);endmodule,格式自由使用空白符提高可读性及代码组织。
Verilog忽略空白符除非用于分开其它的语言标记多行注释,在/* */内,单行注释到行末结束,,整数常量和实数常量,,整数的大小可以定义也可以不定义整数表示为:
字符串中可以使用一些C语言转义(escape)符,如\t \n可以使用一些C语言格式符(如%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”,Verilog中,字符串大多用于显示信息的命令中Verilog没有字符串数据类型,字符串(string),,,转义符及格式符将在验证支持部分讨论 格式符,转义符,格式符%0d表示没有前导0的十进制数,标识符(identifiers),,,标识符是用户在描述时给Verilog对象起的名字标识符必须以字母(a-z, A-Z)或( _ )开头,后面可以是字母、数字、( $ )或( _ )最长可以是1023个字符标识符区分大小写,sel和SEL是不同的标识符模块、端口和实例的名字都是标识符 module MUX2_1 (out, a, b, sel); output out; input a, b, sel; not not1 (sel_, sel); and and1 (a1, a, sel_); and and2 (b1, b, sel); or or1 (out, a1, b1); endmodule,Verilog标识符,,,,标识符(identifiers),,,有效标识符举例: shift_reg_a busa_index _bus3无效标识符举例: 34net // 开头不是字母或“_” a*b_net // 包含了非字母或数字, “$” “_” n@238 //包含了非字母或数字, “$” “_”Verilog区分大小写,所有Verilog关键词使用小写字母。
转义标识符( Escaped identifiers),,,可以包含任何可打印字符反斜杠及空白符不是标识符的一部分 module \2:1MUX (out, a, b, sel); output out; input a, b, sel; not not1(\~sel ,sel); and and1( a1, a, \~sel ); and and2( b1, b, sel); or or1( out, a1, b1); endmodule使用转义符可能会产生一些问题,并且不是所有工具都支持有时用转义符完成一些转换,如产生逻辑图的Verilog网表综合工具输出综合网表时也使用转义符不建议使用转义符转义标识符由反斜杠“\”开始,空白符结束,,Escaped Identifiers,,,转义标识符( Escaped identifiers),,,转义标识符允许用户在标识符中使用非法字符如: \~#@sel \busa+ index \{A,B} top.\ 3inst .net1 // 在层次化名字中转义符 转义标识符必须以空格结束,,,,语言专用标记( tokens),,,系统任务及函数,$
语言专用标记( tokens),,,延时说明,,“#”用于说明过程(procedural)语句和门的实例的延时,但不能用于模块的实例化 module MUX2_ 1 (out, a, b, sel) ; output out ; input a, b, sel ; not #1 not1( sel_, sel); and #2 and1( a1, a, sel_); and #2 and2( b1, b, sel); or #1 or1( out, a1, b1); endmodule门延时有很多类名字:门延时(gate delay),传输延时(propagation delay),固有延时(intrinsic delay),对象内在延时(intra-object delay),编译指导(Compiler Directives),,,,( `)符号说明一个编译指导这些编译指导使仿真编译器进行一些特殊的操作编译指导一直保持有效直到被覆盖或解除`resetall 复位所有的编译指导为缺省值,应该在其它编译指导之前使用,文本替换(substitution) - `define,,,编译指导`define提供了一种简单的文本替换的功能 `define
可提高描述的可读性`define not_delay #1`define and_delay #2`define or_delay #1module MUX2_1 (out, a, b, sel);output out;input a, b, sel; not `not_delay not1( sel_, sel); and `and_delay and1( a1, a, sel_); and `and_delay and2( b1, b, sel); or `or_delay or1( out, a1, b1);endmodule,定义not_delay,使用not_delay,,,文本替换(substitution),,,,解除定义的宏,使用 `undef macro_name使用编译指导`define,可以提高描述的可读性定义全局设计参数,如延时和矢量的位数这些参数可以定义在同一位置这样,当要修改设计配置时,只需要在一个地方修改定义Verilog命令的简写形式 `define vectors_ file "/usr1/chrisz/library/vectors" `define results_ file "/ usr1/chrisz/library/results"可以将`define放在一个文件中,与其它文件一起编译。
文本包含(inclusion) - `include,,,,编译指导`include在当前内容中插入一个文件 格式: `include “
precision是仿真器的仿真时间步若time_unit与precision_unit差别很大将严重影响仿真速度如说明一个`timescale 1s / 1ps,则仿真器在1秒内要扫描其事件序列1012次;而`timescale 1s/1ms则只需扫描103次如果没有timescale说明将使用缺省值,一般是ns。
