0 votes
in Verilog by (200 points)

What is ifdef in Verilog and how do I use it?

2 Answers

0 votes
by (240 points)

Its the conditional compilation directive that is used to include either optional or alternative lines of Verilog HDL source description during compilation.

The `ifdef checks for the definition of a macro. If it is defined, then the lines following the `ifdef are included. If the macro is not defined and an `else directive exists then it includs what is following the `else. The `ifndef compiler directive does the same as `ifdef but for when the macro is not defined. The `elsif directive is a combination of `else and `ifdef. The `endif is borders the lines of code that are controlled by the `if(n)def.

always @(negedge clk_i)
always @(posedge clk_i)
out45_extra <= out45;
assign clk_o_net = out45_extra;

`ifdef USE_Q2
assign clk_o_net = q1;
assign clk_o_net = out45;
0 votes
by (200 points)

When an ifdef is used, the compiler will check if the macro is defined before. If it is defined, the define code will be subsituted, but if not defined or if there is else or elsif it will be ignored.

Hardware Coder Community

© 2022 by Hardware Coder. User contributions are licensed under cc by-sa 4.0 with attribution required. Attribution means a link to the question, answer, user, etc on this site.

This site is owned and operated by Hardware Coder in McKinney, Texas.

Send Us A Message
About Us

By using this site, you agree to the following:

Privacy Policy
Terms and Conditions
DMCA Policy
Earnings Disclaimer
Legal Disclaimer