*******私信博主请加V:FPGA_GO*******
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1,FPGA_Verilog基础篇:Verilog发展进程-优快云博客
2,FPGA_Verilog基础篇:理解Verilog的四值逻辑-优快云博客
3,FPGA_Verilog基础篇:Verilog中数值的表示-优快云博客
4,FPGA_Verilog基础篇:信号声明类型-优快云博客
5,FPGA_Verilog基础篇:模块的端口声明-优快云博客
6,FPGA_Verilog基础篇:verilog语言的操作符-优快云博客
7,FPGA_Verilog基础篇:verilog基本逻辑运算-优快云博客
8,FPGA_Verilog基础篇:verilog关系操作的逻辑运算实现-优快云博客
9,FPGA_Verilog基础篇:veriolg算术运算-优快云博客
10,FPGA_Verilog基础篇:verilog移位操作-优快云博客
11,FPGA_Verilog基础篇:关系操作符简介-优快云博客
12,FPGA_Verilog基础篇:拼接运算符简介-优快云博客
13,FPGA_Verilog基础篇:verilog数值的位宽扩展规则-优快云博客
14,FPGA_Verilog基础篇:verilog移位与拼接实现-优快云博客
15,FPGA_Verilog基础篇:verilog双向inout接口表示_fpga inout端口-优快云博客
16,FPGA_Verilog基础篇:verilog之锁存器和触发器-优快云博客
17,FPGA_Verilog基础篇:verilog之for循环-优快云博客
18,FPGA_Verilog基础篇:verilog之函数用法-优快云博客
19,FPGA_Verilog基础篇:verilog之任务用法-优快云博客
20,FPGA_Verilog基础篇:verilog之任务与函数用法比较-优快云博客
21,FPGA_Verilog基础篇:verilog之宏define介绍-优快云博客
22,FPGA_Verilog基础篇:verilog之条件编译指令介绍-优快云博客
23,FPGA_Verilog基础篇:verilog之参数parameter介绍-优快云博客
24,FPGA_Verilog基础篇:verilog之本地参数localparam-优快云博客
25,FPGA_Verilog基础篇:verilog之generate生成块-优快云博客
26,FPGA_Verilog基础篇:verilog之常数规则-优快云博客
27,FPGA_Verilog基础篇:verilog中整数运算的位宽和符号规则-优快云博客
28,FPGA_Verilog基础篇:verilog中的字符串表示-优快云博客
29,FPGA_Verilog基础篇:verilog中带整数的算术表达式分析-优快云博客
30(结束篇),FPGA_Verilog基础篇:verilog中的数值运算规则总结-优快云博客
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
一般情况下,verilog语言代码中所有的行都参加综合。但是有时我们希望对其中的一部分内容只有在条件满足时才进行综合,也就是对一部分内容指定综合的条件,这就是所谓的“条件编译”。有时,希望当满足条件时对一组语句进行综合,当条件不满足时则对另外一组语句进行综合。这个功能与宏定义联系起来,可以设计更加灵活的模块。条件编译的一般格式如下:
例子1:满足条件进行综合
'ifdef macro_name
operations
'elsif macro_name_elseif
operations_elsif
……
'else
operations_else
'endif
例子2:不满足条件进行综合
'ifndef macro_name
operations
'elsif macro_name_elseif
operations_elsif
……
'else
operations_else
'endif
其中,“macro_name”为前一篇博客所说的宏定义名称;“operations”为条件满足时的操作;还有两个小细节需要注意:是“'elsif”不是“'elseif”;末尾一定要有“'endif”;
例子3:不同的pi赋值
'ifdef TEST_BENCH
real pi = 3.1415926;
'elsif HIGH_ACCURACY
reg [15:0] pi = 31415;
'else
reg [7:0] pi = 31;
'endif
例子4:编译判断结果与宏定义的内容无关
'define TEST_BENCH
'define TEST_BENCH 1
'define TEST_BENCH 0
只要例子4 的“TEST_BENCH”被定义,无论宏定义的值是多少或者没有值,例子3的条件编译都只执行“real pi = 3.1415926;”这个语句。
宏“条件编译”可以与宏定义嵌套,如下面的例子5:
'ifdef TEST_BENCH
'define PI 3.1415926
'elsif HIGH_ACCURACY
'define PI 31415
'else
'define PI 31
'endif
最后说明一下,所有的宏定义和条件编译,乃至后文将要介绍的其它宏,都是在综合软件里起作用,在电路里是不会直接看出来的。
点赞加关注博主(ID:FPGA小飞)的博文,咱们一起学习、一起进步吧~
1631

被折叠的 条评论
为什么被折叠?



