Reg Type
Part of the Fundamentals section of Coddy's Verilog journey — lesson 7 of 90.
Reg is the second main data type in Verilog. Unlike wire, a reg stores a value. It is a variable that holds its value until something changes it.
regcan store valuesregis used inalwaysblocksregdoes NOT mean "register" in hardware—it just means “storage”
Declaring a reg
reg x; // Single-bit reg
reg y, z; // Multiple regs on one lineHow reg Works
module reg_example;
reg x;
initial begin
x = 0; // x becomes 0
$display("x = %d", x); // Prints: x = 0
x = 1; // x becomes 1
$display("x = %d", x); // Prints: x = 1
end
endmoduleChallenge
What to do:
- Add a reg called
count
Cheat sheet
reg stores a value and holds it until changed. Used inside always or initial blocks.
reg x; // Single-bit reg
reg y, z; // Multiple regsinitial begin
x = 0; // assign value
x = 1; // update value
endTry it yourself
module counter(
input clk,
input reset,
output out // wire by default (remove reg)
);
// Declare reg count here
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