Verilog基础:标识符的定义位置
相关阅读
Verilog基础https://blog.csdn.net/weixin_45791458/category_12263729.html?spm=1001.2014.3001.5482
Verilog中的标识符种类有很多,本文将讨论这些标识符的定义位置并给出相关例子。
reg类型
模块命名空间
module test;*****reg [7:0] count_reg; // 模块命名空间中定义reg信号*****endmodule
注意事项:如果reg类型不是数组形式,则可以赋初值。
块命名空间
命名块
module test;*****always@(*) begin: areg [7:0] count_reg; // 块命名空间中定义reg信号***** end*****endmodule
注意事项:reg类型不可以赋初值,且必须在命名块中的所有语句之前声明。
函数
module test;*****function func(input a);reg [7:0] count_reg; // 块命名空间中定义reg信号begin:***** endendfunction*****endmodule
注意事项:reg类型不可以赋初值,且必须在函数中的所有语句之前声明。
任务
module test;*****task task1;reg [7:0] count_reg; // 块命名空间中定义reg信号begin:***** endendtask*****endmodule
注意事项:reg类型不可以赋初值,且必须在任务中的所有语句之前声明。
生成块命名空间
module test;*****generategenvar a;for(a=0; a<5; a=a+1) begin // 对于Verilog 2005标准,无需给块命名*****reg [7:0] count_reg; // 生成块命名空间中定义reg信号***** endendgenerate*****endmodule
注意事项:如果reg类型不是数组形式,则可以赋初值。
integer类型
与reg类型相同。
real类型
与reg类型相同。
time类型
与reg类型相同。
realtime类型
与reg类型相同。
net大类
net大类包括wire、wand、wor、tri、triand、trior、tri0、tri1、trireg、uwire、supply0、supply1类型。
模块命名空间
module test;*****wire [7:0] count_wire; // 模块命名空间中定义wire信号*****endmodule
注意事项:如果net大类不是数组形式,则可以赋值(表达式可以是常量也可以是变量);如果为net大类指定了驱动强度,则必须赋值。
生成块命名空间
module test;*****generategenvar a;for(a=0; a<5; a=a+1) begin // 对于Verilog 2005标准,无需给块命名*****wire [7:0] count_wire; // 生成块命名空间中定义wire信号***** endendgenerate*****endmodule
注意事项:如果net大类不是数组形式,则可以赋值(表达式可以是常量也可以是变量);如果为net大类指定了驱动强度,则必须赋值。
event类型
模块命名空间
module test;*****event tt; // 模块命名空间中定义event*****endmodule
块命名空间
命名块
module test;*****always@(*) begin: aevent tt; // 块命名空间中定义event***** end*****endmodule
注意事项:event类型必须在命名块中的所有语句之前声明。
函数
module test;*****function func(input a);event tt; // 块命名空间中定义eventbegin:***** endendfunction*****endmodule
注意事项:event类型必须在函数中的所有语句之前声明。
任务
module test;*****task task1;event tt; // 块命名空间中定义eventbegin:***** endendtask*****endmodule
注意事项:event类型必须在任务中的所有语句之前声明。
生成块命名空间
module test;*****generategenvar a;for(a=0; a<5; a=a+1) begin // 对于Verilog 2005标准,无需给块命名*****event tt; // 生成块命名空间中定义event***** endendgenerate*****endmodule
localparam类型
模块命名空间
module test;*****localparam WIDTH = 5; // 模块命名空间中定义localparam*****endmodule
块命名空间
命名块
module test;*****always@(*) begin: alocalparam WIDTH = 5; // 块命名空间中定义localparam***** end*****endmodule
注意事项:localparam类型必须在命名块中的所有语句之前声明。
函数
module test;*****function func(input a);localparam WIDTH = 5; // 块命名空间中定义localparambegin:***** endendfunction*****endmodule
注意事项:localparam类型必须在函数中的所有语句之前声明。
任务
module test;*****task task1;localparam WIDTH = 5; // 块命名空间中定义localparambegin:***** endendtask*****endmodule
注意事项:localparam类型必须在函数中的所有语句之前声明。
生成块命名空间
module test;*****generategenvar a;for(a=0; a<5; a=a+1) begin // 对于Verilog 2005标准,无需给块命名*****localparam WIDTH = 5; // 生成块命名空间中定义localparam***** endendgenerate*****endmodule
parameter类型
与localparam类型类似,区别在于parameter类型不能在生成块命名空间中定义。
function类型
模块命名空间
module test;*****function func(input a); // 模块命名空间中定义function***** endfunction *****endmodule
生成块命名空间
module test;*****generategenvar a;for(a=0; a<5; a=a+1) begin // 对于Verilog 2005标准,无需给块命名*****function func(input a); // 生成块命名空间中定义function***** endfunction ***** endendgenerate*****endmodule
task类型
与function类型相同。