What does reg mean in verilog




















Such entities with a width more than 1 are called vectors as we shall see in the next article. It is illegal to redeclare a name already declared by a net, parameter or variable as shown in the code below. A variable on the other hand is an abstraction of a data storage element and can hold values.

A flip-flop is a good example of a storage element. Verilog data-type reg can be used to model hardware registers since it can hold values between assignments. Note that a reg need not always represent a flip-flop because it can also be used to represent combinational logic. In the image shown on the left, we have a flip-flop that can store 1 bit and the flip-flop on the right can store 4-bits. An integer is a general purpose variable of bits wide that can be used for other purposes while modeling hardware and stores integer values.

A time variable is unsigned, bits wide and can be used to store simulation time quantities for debugging purposes. The last assignment determines the current value of the variable. Initially, Verilog used the keyword reg to declare variables representing sequential hardware registers. Eventually, synthesis tools began to use reg to represent both sequential and combinational hardware as shown above and the Verilog documentation was changed to say that reg is just what is used to declare a variable.

SystemVerilog renamed reg to logic to avoid confusion with a register — it is just a data type specifically reg is a 1-bit, 4-state data type.

However people get confused because of all the old material that refers to reg. Just forget about it and use logic from now on. Another distinctive characteristic of an HDL is that it models massive amounts of parallel processes. Modules are containers representing processes modeled at different levels of abstraction.

Groups of primitives and modules pass values to each other via networks of signals. In Verilog, a wire declaration represents a network net of connections with each connection either driving a value or responding to the resolved value being driven on the net. The output of each of these concurrent processes drives a net in what is called a continuous assignment because the process continually updates the value it wants to drive on the net.

It holds a value assigned to it until the next assignment. Verilog reg is probably the most common variable data type. Other variable data types include integer , time , real , realtime. Verilog net data types can only be assigned values by continuous assignments.

This means using constructs like continuous assignment statement assign statement , or drive it from an output port. A continuous assignment drives a net similar to how a gate drives a net. The expression on the right hand side can be thought of as a combinatorial circuit that drives the net continuously.

Verilog variable data types can only be assigned values using procedural assignments. This means inside an always block, an initial block, a task , a function. The assignment occurs on some kind of trigger like the posedge of a clock , after which the variable retains its value until the next assignment at the next trigger. This makes variables ideal for modeling storage elements like flip-flops.

SystemVerilog introduces a new 2-state data type—where only logic 0 and logic 1 are allowed, not X or Z—for testbench modeling. To distinguish the old Verilog 4-state behaviour, a new SystemVerilog logic data type is added to describe a generic 4-state data type. What used to be data types in Verilog, like wire , reg , wand , are now called data objects in SystemVerilog. Wire , reg , wand and almost all previous Verilog data types are 4-state data objects. Bit , byte , shortint , int , longint are the new SystemVerilog 2-state data objects.

There are still the two main groups of data objects: nets and variables. All the Verilog data types now data objects that we are familiar with, since they are 4-state, should now properly also contain the SystemVerilog logic keyword.

There is a new way to declare variables, beginning with the keyword var. If the data type 2-state or 4-state is not specified, then it is implicitly declared as logic. Below are some variable declaration examples. For everyday usage in RTL design, you can pretty much forget all of that! The SystemVerilog logic keyword standalone will declare a variable, but the rules have been rewritten such that you can pretty much use a variable everywhere in RTL design.

Hence, you see in my example code from other articles, I use SystemVerilog logic to declare variables and ports. When you use SystemVerilog logic standalone this way, there is another advantage of improved checking for unintended multiple drivers.

Although, numbers can be converted from one form to another, but it should be avoided as it may results in errors which are difficult to find.

In this section, various synthesizable operators of Verilog are discussed, which are shown in Table 3. Four bitwise operator are available in verilog i. Further, we can combine these operators to define new operators e. We already see the equality relational operation i. Further, five relational operators are defined in verilog i. Further, three relational operators are defined in verilog i.

Verilog provides 4 types of shif operators i. Also, conditional expression can be cascaded as shown in Listing 3. Multiplexer is a combinational circuit which selects one of the many inputs with selection-lines and direct it to output. The design generated in Fig. Therefore, Fig. Further, Fig. In Listing 3. Then this value is used in line 10 and Suppose we want to change the constant value to 4.

Now, we need to change it only at one place i. In this way, we can remove the hard literals from the codes.



0コメント

  • 1000 / 1000