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 inputsIn the example above, the value of
awill change wheneverborcchanges.Ports: Wires can be used for
inputandinoutports of modules. The values driven onto a wire can come from continuous assignments or from ports of instantiated modules.No Storage: Unlike variables (like
regorint), awiredoes not store a value. It's essentially a conduit that connects parts of your design.Driven by Only One Source: A
wireshould 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
regdata 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
wirewhich takes its value from continuous assignments, theregtype gets its value from procedural assignments, commonly withinalways,initial,task, orfunctionblocks.reg my_reg; always @(posedge clk) my_reg <= input1 & input2; initial begin my_reg = 1'b0; // initialization of reg endHere,
my_regwill be assigned a new value with every positive edge of theclksignal. Theinitialblock ensures thatmy_regstarts with a known value at the beginning of the simulation.Multiple Assignments: A
regcan 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; endIn this example, the value of
rchanges over time during the simulation.Array Declaration:
regdata types can also be used to declare arrays. This feature is useful for handling vector signals and storing multiple values.Module Ports: Although the
regdata type can connect to module ports, it cannot be declared as aninputport directly. It is, however, valid foroutputandinout.Storage Properties: Unlike
wire, theregdata 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
wireis a physical connection typically driven by a continuous assignment (assignstatement) or a module output, while aregrepresents a storage element and can be driven within procedural code blocks likealwaysorinitial.
Have a Question?
Feel free to ask your question in the comments below.
Please Login to ask a question.
Login Now