Comments
Part of the Fundamentals section of Coddy's Verilog journey — lesson 5 of 90.
Comments are notes in your code that the computer ignores. They help explain what your code does.
Two Types of Comments:
1. Single-line comment
// This is a single-line comment
assign c = a & b; // Comments can go after code tooEverything after // is ignored by the computer.
2. Multi-line comment
/* This is a multi-line comment
It can span several lines
Useful for longer explanations */
assign c = a & b;Everything between /* and */ is ignored.
Why Use Comments?
- Explain what your module does
- Describe what each input and output is for
- Make code easier to understand
- Leave notes for yourself or others
Challenge
In this challenge, you need to add comments to an existing module.
What to do:
Add a single-line comment at the top explaining what the module does
// This is a module called 'test'Add a multi-line comment at the end of the code explaining what the counter does
/** 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.*/
Cheat sheet
Comments in Verilog are ignored by the compiler and used to explain code.
Single-line comment — everything after // is ignored:
// This is a comment
assign c = a & b; // Inline commentMulti-line comment — everything between /* and */ is ignored:
/* This spans
multiple lines */
assign c = a & b;Try it yourself
module test(
input clk,
input reset,
output reg [3:0] count
);
initial $display("Comments are ignored by the computer");
endmoduleThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic