verilog操作符
逻辑操作符:两个表达式之间进行
&&
||
!
位操作符:两个变量之间进行
&
|
^
~^
缩位操作符:矢量的每个bit都参与操作(从左向右),结果为1bit位宽
&
|
^
~&
~|
~^
算术操作符
==
!=
>
>=
<
<=
+
-
* //乘
/ //除
% //求余
** //指数运算
其他
~//按位 “非”
例如:
wire a,b;
assign b=~a;//等效于 assign b[0] =~a[0]; assign b[1]=~a[1]
{} //拼接
<< //左移 =>*2**n
>> // 右移 =>/2**n
? //条件运算符
可重用和模块化设计
parameter
在module内部定义parameter
module module_name #(parameter FIFO_PTR =4,
FIFO_WIDTH =32)
(...,
...);
input [FIFO_WIDTH -1:0] wr_data;
input [FIFO_WIDTH -1:0] rd_data;
......
endmodue
include 进来 parameters.vh
module module_name
(...,
...);
input ...;
output...;
...;
`include /*/*/parameters.vh
endmodule
verilog 函数--function(不能有时间语句 wait @ #)
函数具有一个函数名,一个或多个input,以及一个output
module module_name
...
function [n:0] output_name;
input [] a;
input [] b;
...
begin
output_name= ...;
end
endfunction
调用function;
...
调用function;
...
endmodule
generate :简化设计流程,提高电路的可重用性
parameter END_NUMBER =10;
generate
genvar i;
for (i=0; i<(END_NUMBER);i=i+1)
begin
...
end
endgenetate
对一个电路模块多次例化
generate
genvar n;
for(n=0; n< NUM_OF_PORTS;n=n+1)
begin :switch_port_inst
switch_port switch_port_u
(.a (in1[n]),
.b (in2[n]),
.c (out1[n]),
.d (out2[n]),
end
`ifdef 条件编译
`ifdef
`else if
`else if
`else
`endif
PS:`ifdef `endif有且只能出现一次;`else if 可出现{0,};`else {0,1}
数组、多维数组
例子
reg [31:0] memory[0:127];