Verilog 注释语句与文件头
Verilog语法与C语言由许多一致的地方, 特别是注释语句几乎一样, 也提供了两种注释方式,分别为行注释//与段注释/* … */。注释不作为代码的有效部分,只是起到注释的作用,提高程序的可读性。编译器在编译时自动忽略注释部分。
- 行注释语句//
一种是由双斜杠”//”构成的注释语句,只注释一行,即从 //开始到本行末都是注释部分。行注释常用来说明该行代码的含义,意图及提示等信息,也可以注释一行代码。
如:
wire signed [3:0] a; // 定义有符号wire类型向量a。
wire signed [3:0] b;
//wire signed [3:0] c;
上面三条语句中第三条被注释了,因此编译器在编译时自动忽略该条语句。
- 段注释语句/*…*/
段注释语句可以注释一段内容。例:
`timescale 1ns/1ps module tb ( ); reg [3:0] a, b, c; wire [3:0] d; wire [3:0] e; initial begin a ='b0; b ='b0; c ='b0; #10 a ='d7; b ='d9; c ='d12; #10 a ='b11x1; end /* cmp cmp_dut ( .a (a), .b (b), .c (c), .d (d), .e (e) ); */ endmodule
在上例中由符号“/*”与符号“*/”包起来的一段内容是注释部分,编译器在编译时自动忽略。
- 文件头:
一般好的习惯在每个工程文件的开头由注释语句组成一段说明(或声明)文件,指明文件创建日期,修改日期,作者,版权,及该文件简短说明等。工程师在编写文件时要保持一个良好的习惯,为以后代码维护和版权维护带来方便。
Xilinx 推荐的格式如下:
//////////////////////////////////////////////////////////////////////////////// // Company: <Company Name> // Engineer: <Engineer Name> // // Create Date: <date> 创建时间 // Design Name: <name_of_top-level_design> 设计名称 // Module Name: <name_of_this_module> 本模块名称 // Target Device: <target device> 使用的目标器件 // Tool versions: <tool_versions> 开发工具的版本号 // Description: 描述 // <Description here> // Dependencies: 依赖 // <Dependencies here> // Revision: 修订版 // <Code_revision_information> // Additional Comments: // <Additional comments> //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // 公司: Fraser Innovation Inc. // 工程师:庄乾起 // 创建日期:2021 年 2月18 // 设计名称: 注释 // 模块名: // 目标器件: cyclone 10lp // 工具软件版本号: Quartus II 20.3 // 描述: // <Description here> // 依赖文件: // <Dependencies here> // 修订版本: // rev1.1 // 额外注释: // 待定 //////////////////////////////////////////////////////////////////////////////// module aaa ( input clk, input a, output b, input reset ); .... .... endmodule