Wire and Reg
Wire
In SystemVerilog, the wire
data type represents physical wires or connections in hardware. A wire does not store a value but merely acts as a conduit to propagate it from one point in the design to another.
Characteristics and Usage:
4-State: Wires in SystemVerilog can be in one of four states:
0
,1
,X
(unknown), orZ
(high-impedance). This capability allows for more accurate modeling of real-world electronic behaviors.Continuous Assignments: Wires are typically used with continuous assignments. When the right-hand side (RHS) of a continuous assignment changes, the new value is immediately driven onto the wire.
wire a; assign a = b & c; // b and c are inputs
In the example above, the value of
a
will change wheneverb
orc
changes.Ports: Wires can be used for
input
andinout
ports of modules. The values driven onto a wire can come from continuous assignments or from ports of instantiated modules.No Storage: Unlike variables (like
reg
orint
), awire
does not store a value. It's essentially a conduit that connects parts of your design.Driven by Only One Source: A
wire
should only be driven by one source. Having multiple drivers for a single wire will lead to contention and result in an unknown value (X
) on the wire.
Reg
In SystemVerilog, the reg
type is not indicative of hardware registers but rather symbolizes a data object capable of holding a value across different simulation time steps. Its name might initially mislead beginners, but its primary use is to store a value for procedural assignments, typically inside procedural blocks.
Characteristics and Usage:
4-State Value: The
reg
data type in SystemVerilog can take on one of four states:0
,1
,X
(unknown), orZ
(high-impedance). This four-state capability models the uncertainties often encountered in digital logic simulations.Procedural Assignments: Unlike the
wire
which takes its value from continuous assignments, thereg
type gets its value from procedural assignments, commonly withinalways
,initial
,task
, orfunction
blocks.reg my_reg; always @(posedge clk) my_reg <= input1 & input2; initial begin my_reg = 1'b0; // initialization of reg end
Here,
my_reg
will be assigned a new value with every positive edge of theclk
signal. Theinitial
block ensures thatmy_reg
starts with a known value at the beginning of the simulation.Multiple Assignments: A
reg
can be assigned multiple times within a procedural block, but it retains the value of the last assignment after the block completes.reg r; initial begin r = 1'b0; #10 r = 1'b1; #20 r = 1'b0; end
In this example, the value of
r
changes over time during the simulation.Array Declaration:
reg
data types can also be used to declare arrays. This feature is useful for handling vector signals and storing multiple values.Module Ports: Although the
reg
data type can connect to module ports, it cannot be declared as aninput
port directly. It is, however, valid foroutput
andinout
.Storage Properties: Unlike
wire
, thereg
data type can hold and remember its value between simulation time steps.
The reg
data type's nuances in SystemVerilog are foundational. Its proper understanding and application are pivotal for accurate simulations and can preempt potential pitfalls in design or verification phases.
A
wire
is a physical connection typically driven by a continuous assignment (assign
statement) or a module output, while areg
represents a storage element and can be driven within procedural code blocks likealways
orinitial
.
Have a Question?
Feel free to ask your question in the comments below.
Please Login to ask a question.
Login Now