- 命名开头不能使用数字和标识符
- 分大小写
- 行注释//
- 块注释/*xxxxx*/
- value : 0,1,x(悬空态,unknown logic),z(高阻态)
- Verilog中数字表达形式 12‘0 3zx7 = 011zzzxxx111
- Bit extension: 0,x or z 可以extend 。 其他extend前面加0
- Net: 逻辑驱动的硬件导线,不连接时是‘z’态,有四种线分别是 wire, wand,wor,tri
- 线与,线或逻辑一般不用因为会造成一条线被2种驱动
- wire Y = A&B ; 省略 assign的写法
- always 模块里面的左边的变量必须是reg型
- 阻塞 = , 值传递有顺序
- 非阻塞 <=, 用在时序电路种 end的时候值同步传递
- integer i,k; real r; integer是整数形式没有赋初始值,real是小数形式初始值0.0. r = 2.9; k = r; (k = 3 四舍五入)
- time my_time; (declaration) my_time = $time; // get current sim_time 返回仿真时间
- vector 向量 reg [1:4] busB ; wire [3:0] busA;
- array 数组 reg [7:0] mem[0:1023]; // 1024 8 bit regs 对memory进行建模
- array limitation:
1.不能访问数组子区间。 vector可以
2.没有多个方向的数组 reg var[1:10] [1:100]; wrong!! Systemverilog 可以
3. real 数据形式没有数组
- Strings 8位8位二进制ASCⅡ码的形式表示所以有 reg [8*13:1] 13个字符共104位
- escaped chars(转义符):
\n newline
\t tab
%% %
\\ \
\" "
- logic operators: && and, || or, ! not 结果是 ONE bit
x || 0 = x
x && 0 = 0 (强调)
- bitwise operators
& bitwise AND
| bitwise OR
~ bitwise NOT
^ bitwise XOR
~^ or ^~ bitwise XNOR
- reduction operator
a = 4’b1001;
c = | a; // c = 1|0|0|1 = 1
& AND
| OR
^ XOR
~& NAND
~| NOR
~^ or ^~ XNOR
- shift operators 总是用0补充,移位后与原数相同位数
>> shift right
<< shift left
-
concatenation operator
operands must be sized
catr = {4{a}, b, 2{c}}; 4倍a 2倍c拼接 -
relational operators
>
<
>=
<=
- equality operators
== logical equality
!= logical inequality
=== case equality
!== case equality
4’b 1z0x == 4’b 1z0x -> x
4’b 1z0x != 4’b 1z0x -> x
4’b 1z0x === 4’b 1z0x -> 1
4’b 1z0x !== 4’b 1z0x -> 0
- conditional operator
(sel)?A :B 对选择器进行建模
- arithmetic operators
+,-,*,/,%
if any operand is x the results is x
Negative registers:
regs can be assigned negative but are treated as unsigned
reg [15:0] regA;
regA = -4’d12; // stored as 216 -12 = 65524 类似补码
regA/3 evaluates to 21861
Negative integers:
integer intA;
int A = -12/3; // evaluates to -4 (no base spec)
intA = -'d12/3; // evaluates to 1431655761(base spec)
-4’d12 表示 2^32-12 有拓展,所以除以3之后结果是1431655761。
如果使用’sd 就是有符号位的 0~9 -4‘sd12 就会等于3
- Operator Precedence (优先级)—终极秘诀 加括号
- Hierarchical Design