Basic system verilog constructs
- case sensitive
- no implicit declaration of variables
- white space insensitive
- naming convention: use
_to separate words, e.g.,data_in,addr_out, CANNOT start with number - block always end with
end,endmodule,endfunction, starts withbeginormodule,function
module
| basic_module.sv | |
|---|---|
Behavioral modeling
alwaysblocks: used to model sequential and combinational logicinitialblocks: used for simulation purposes, runs once at time 0always_comb: used for combinational logicalways_ff: used for sequential logic (flip-flops)always_latch: used for latchesposedgeandnegedge: used to trigger on rising or falling edges of a signal=for blocking assignments,<=for non-blocking assignments. we have to useassignfor combinational logic outside ofalwaysblocks (dataflow modeling)
note: behavioral modeling utilize full language features (that is both synthesizable and non-synthesizable constructs)
- synthesizable constructs can be converted to hardware
- non-synthesizable constructs are used for simulation and verification only, for example, `initial` block and
`$display`
Dataflow modeling
- uses continuous assignments with the
assignkeyword - describes the flow of data through the circuit
| dataflow_modeling.sv | |
|---|---|
Gate-level modeling
- describes the circuit in terms of logic gates and their interconnections
- uses built-in gate primitives like
and,or,not, etc.

example: code for a 2-4 decoder using different modeling styles
truth table
| A1 | A0 | Y0 | Y1 | Y2 | Y3 |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 |
Parameter declaration
- use
parameterkeyword to declare constants - parameters can be used to make modules more flexible and reusable
localparamcan be used to declare local parameters that cannot be overridden during module instantiation
| parameter_example.sv | |
|---|---|
variables
values
- 0 : logic low
- 1 : logic high
- x : uninitialized / unknown
- z : high impedance
variable: 4 state (variable that can take on 4 values: 0, 1, x, z)
net: 2 state (variable that can take on 2 values: 0, 1)
data type
wire: 4 state net, it can only have 1 source (1 continuous assignment or one module output)wand,wor: wired AND, wired OR (multiple drivers, resolved to AND or OR respectively)tri(logic),tri0,tri1: tri-state net, tri0 defaults to 0 when not driven, tri1 defaults to 1 when not drivenreg,logic: 4 state variable (reg is deprecated, logic is not available in verilog)-
bit: 2 state variable
example:
Module A
module using_wire (A, B, C, D, f);
input A, B, C, D;
output f;
wire f;
assign f = A & B;
assign f = C | D;
endmodule
Module B
module using_wand (A, B, C, D, f);
input A, B, C, D;
output f;
wand f;
assign f = A & B;
assign f = C | D;
endmodule
Module C
module using_tri (A, B, C, D, f);
input A, B, C, D;
output f;
tri f;
assign f = A & B;
assign f = C | D;
in this case, using_wire will cause a multiple driver error, using_tri will cause synthesize error, because tri net
only works if the divers can output 1'bz to get off the buz. while using_wand will resolve f to the AND of the two
assignments. assignments.
the final value of f in the using_wand module will be (A & B) & (C | D).
