注释
本课属于 Coddy Verilog 学习旅程的“基础知识”单元。第 4 课,共 90 课。
注释是代码中的备注,计算机会忽略它们。注释可以帮助解释代码的作用。
两种注释:
1. 单行注释
// 这是一条单行注释
assign c = a & b; // 注释也可以写在代码后面// 后面的所有内容都会被计算机忽略。
2. 多行注释
/* 这是一个多行注释
它可以跨越多行
适合用于较长的说明 */
assign c = a & b;/* 和 */ 之间的所有内容都会被忽略。
为什么要使用注释?
- 说明你的模块的作用
- 描述每个输入和输出的用途
- 让代码更容易理解
- 为自己或他人留下备注
挑战
在这个挑战中,你需要为现有模块添加注释。
要做什么:
在顶部添加一条单行注释,说明模块的作用
// This is a module called 'test'在代码末尾添加一条多行注释,说明计数器的作用
/** It has a clock input, a reset input,* and a 4-bit output called count.* The initial block prints a message* to show that comments are ignored.*/
亲手试试
module test(
input clk,
input reset,
output reg [3:0] count
);
initial $display("Comments are ignored by the computer");
endmodule这节课包含一个小测验。开始学习即可作答,并记录你的进度。
基础知识中的所有课
自己练习: Verilog 在线编译器