2
\$\begingroup\$

If I want to model a simple register I would expect to have an internal 'reg' element to hold the value and I would connect this with a 'wire' output. The reg drives an internal output.

However, I've looked up several examples and most use an output of type 'reg'. I don't understand why you would do that. Aren't you storing the value in two places this way? Is there a difference in behavior?

\$\endgroup\$

1 Answer 1

7
\$\begingroup\$

The way to choose how to declare your signal is not by how it will be physically instantiated, but by how you will syntactically assign its value.

If the signal is driven by assignments in a procedural block (a block beginning with always or initial), then it must be declared as reg.

If the signal is driven by continuous assignment (an assign statement) or is the output of a module instance, then it must be declared as wire (or one of its variants like wor or wand), or as an output without the reg qualifier.

A reg signal might be physically the output of either a latch or a flip-flop or of combinatorial logic (for example, there's a very common way of inferring a combinatorial multiplexer using an always block). A wire might be physically the output of a latch or a flip-flop or combinatorial logic (for example if the flip-flop is within a submodule).

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Thx! So it is really a language / simulation choice and both options could result in the same physical implementation? \$\endgroup\$
    – ErwinM
    Commented Feb 24, 2017 at 18:28
  • 1
    \$\begingroup\$ Yes, that's it exactly. \$\endgroup\$
    – The Photon
    Commented Feb 24, 2017 at 18:30
  • \$\begingroup\$ please seehttp://go.mentor.com/wire-vs-reg \$\endgroup\$
    – dave_59
    Commented Feb 26, 2017 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.