Verilog
:material-circle-edit-outline: 约 420 个字 :fontawesome-solid-code: 50 行代码 :material-clock-time-two-outline: 预计阅读时间 5 分钟
Structure of a Verilog Program¶
- A Verilog program is structured as a set of modules, which may represent anything from a collection of logic gates to a complete system. Modules are similar to classes in C++, although not nearly as powerful. A module specifies its input and output ports, which describe the incoming and outgoing connections of a module. A module may also declare additional variables. The body of a module consists of:
initial
constructs, which can initialize reg variables- Continuous assignments, which define only combinational logic
- always constructs, which can define either sequential or combinational logic
- Instances of other modules, which are used to implement the module being defined
Representing Complex Combinational Logic in Verilog¶
Continuous Assignments¶
Verilog | |
---|---|
- A continuous assignment, which is indicated with the keyword assign, acts like a combinational logic function: the output is continuously assigned the value, and a change in the input values is reflected immediately in the output value.
Warning
Using always Blocks for Combinational Logic¶
Note
Verilog | |
---|---|
- When an always block is specifying combinational logic, the sensitivity list should include all the input signals. If there are multiple Verilog statements to be executed in an always block, they are surrounded by the keywords begin and end, which take the place of the { and } in C
=
: blocking assignment, which means that the right-hand side is evaluated and assigned to the left-hand side before the next statement is executed.<=
: nonblocking assignment, all right-hand sides of the assignments in an always group are evaluated and the assignments are done simultaneously
Verilog | |
---|---|
Beware
Tips
- Place all combinational logic in a continuous assignment or an always block.
- Make sure that all the signals used as inputs appear in the sensitivity list of an always block.
- Ensure that every path through an always block assigns a value to the exact same set of bits