The difference between parameter and define in Verilog

Source: Internet
Author: User
Tags valid

1. Grammar

Statement:

Parameter data = 8 ' D14;

' Define Data 8 ' D14

Use:
Data

' Data

2. Scope

Parameter the file that acts on the Declaration, ' define reads from the compiler until the end of the compilation is valid, or the ' undef command invalidates it.

If you want parameter or ' define to work on the entire project, you can write the following declaration in a separate file and use ' include to have each file contain a declaration file:

' ifndef data

' Define data 8 ' D14

Or

parameter data = 8 ' D14;

' endif

' Define can also be written at the top of the file that the compiler compiles first. The compiler can usually define the compilation order or start compiling from the bottommost module. So write it down at the bottom.

3. Difference

The parameter can be used as a parameter pass at the time of the instantiate.

The difference is quite large when using the state machine. The definition of a state machine can be defined with parameter, but it is not recommended to use the ' Define macro definition because the ' Define macro definition automatically replaces the macro defined in the entire design at compile time, and parameter only defines the parameters inside the module. The defined parameters are not confused with other state machines outside the module. For example, in a project there are two module each containing an FSM, if the design has the state of the name idle, if the use of ' Define macro definition will be confused, if the use of parameter will not cause any adverse effects.

Once the ' define instruction is compiled, it is valid throughout the compilation process. For example, a defined constant can be called in another file by using the ' define directive ' in the other file. Until it encounters ' undef;parameter only valid in the defined file, it is not valid in other files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.