Introduction To Verilog
Introduction To Verilog
DATA TYPES
reg (register)-holds a value. (It need not necessarily correspond to an actual register in an
implementation, although it often will.
CONSTANTS
-represented by prefixing the value with a decimal number specifying its size in bits.
-Example: 4’b0100 specifies a 4-bit binary constant with the value 4, as does 4’d4.
VALUES
OPERATORS
❖ Verilog provides the full set of unary and binary operators from C, including
⮚ The arithmetic operators (+,-,*,/),
⮚ The logical operators (&, |, ),
⮚ The comparison operators (==, !=, >, <, <=, >=),
⮚ The shift operators (<<, >>)
⮚ Conditional operators (?, which is used in the form condition ? expr1: expr2 and returns expr1 if
the condition is true and expr2 if it is false).
❖ A Verilog Program is structured as a set of modules, which may represent anything from a collection
of logic gates to a complete system.
❖ A Module specifies its input and output ports, which describe the incoming and outgoing
connections of a module.
❖ A Module may also declare additional variables.
❖ The body of a module consists of
⮚ Initial constructs, which can initialize reg variables
⮚ Continuous assignments, which define only combinational logic
⮚ Always constructs, which can define either sequential or combinational logic
⮚ Instances of other modules, which are used to implement the module being defined.
KEY THINGS TO REMEMBER
● Assign: continuous assignments. Any change in the input is reflected immediately in the output.
● Wires may be assigned values only with continuous assignments.
ALWAYS
● always @(A, B, Sel) – means that the block is reevaluated every time any one of the signals in the
list changes value.
● NOT A FUNCTION CALL
● If no sensitive list, always evaluated
● Always keep in mind that it is used to describe the behavior of a piece of hardware you wish to
design. Basically, it is used to tell Verilog what kind of gates should be used.
ALWAYS BLOCK CONTINUED
● Only reg variables can be assigned values in the always block – output reg 0;
● When we want to describe combinational logic using an always block, care must be taken to
ensure that the reg does not synthesize into a register.