找回密码
 注册
关于网站域名变更的通知
查看: 416|回复: 1
打印 上一主题 下一主题

verilog 基础语法-数据类型 常量 变量

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-3-8 11:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
verilog 基础语法-数据类型 常量 变量

+ q; p$ V9 B, Y, L( t4 S1 ?* k# O. j& S: J6 v/ H8 D2 q4 ?; c- b/ @

' a5 X$ G0 E6 c8 L1 M    常量:
! A. i. a- L& y' F1 e( k" R&nbsp; &nbsp; &nbsp; &nbsp; 整数:<位宽 num'><进制 b|o|d|h><数字>,例如 4'b1010; O: e* M4 Y, C
&nbsp; &nbsp; &nbsp; &nbsp; x值(不定值)和z值(高阻值,也可用?代替)
& Z, b2 q9 y! r" z) T&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x和z可以标识某一位或者某一个数字% j( v" u% Z) A1 L' X7 W
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4'b10x0,4'bx,4'b101z,4'bz,4'b?7 k* ]4 [6 u. t7 g# U0 h% x$ m
&nbsp; &nbsp; &nbsp; &nbsp; 负数:整数最前面加-/ Q8 y, }$ U$ o/ ]) c& h
&nbsp; &nbsp; &nbsp; &nbsp; 下划线:分割数字部分,更加易读(8'b1000_1000)& T$ n6 d8 R; t  k/ u. T$ Q
&nbsp; &nbsp; 参数:parameter
$ ]) U! p/ k% E* K/ @3 O0 B+ s* i&nbsp; &nbsp; &nbsp; &nbsp; parameter 参数名=表达式;
, ^$ O1 a. P: m5 d&nbsp; &nbsp; &nbsp; &nbsp; 表达式只能是数字或者定义过的参数
4 {6 l" }$ z  R2 G- P&nbsp; &nbsp; 变量:
+ D& `- [& u; f, s&nbsp; &nbsp; &nbsp; &nbsp; wire型:wire [n-1:0] 数据名;1 h2 O9 U6 @, ?& q: z
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wire表示信号,常用来表示assign关键字指定的组合逻辑信号
' p9 V- n  L' T6 _8 p. F/ n5 _&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wire型信号可以用作输入,输出
5 m& ^- ~7 e" f( I% }7 g' M6 N* y&nbsp; &nbsp; &nbsp; &nbsp; reg型:reg [n-1:0] 数据名;
0 q1 z+ G4 f) E: w5 A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 对存储单元的抽象
3 [$ W, Q- e! \" p/ C2 _# C" v&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 常用来表示always模块内的指定信号,常代表触发器
/ P/ n9 C1 i9 J; N# k&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; always块内被赋值的每一个信号都必须定义为reg型
* `* o1 d  a4 d8 p: w3 e* x+ D7 w1 Q  W&nbsp; &nbsp; &nbsp; &nbsp; memory型:reg [n-1:0] 存储器名[m-1:0];
8 {/ ^. E/ ~. z&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reg [n-1:0]表示基本存储单元的大小
$ p% c+ R% h) K! @4 M  v&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 存储器名[m-1:0]表示基本存储单元的个数,存储空间的容量
* B2 b% p0 q  b9 `/ t% M% ?/ t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 对存储器进行地址索引的表达式必须是常数表达式# E) @9 B9 o9 j; ?* Z& q, l
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 一个n位寄存器可以在一条赋值语句里进行赋值,而一个完整的存储器不行
2 x9 |8 C. O* S# W&nbsp; &nbsp; 运算符及表达式:
! B3 }" d" R$ @: p1 D8 H# K4 j&nbsp; &nbsp; &nbsp; &nbsp; 基本运算符:+ - * / %
  r' B% X; m2 s- ?) j&nbsp; &nbsp; &nbsp; &nbsp; 位运算符:~ & | ^ ^~$ B7 a' K; k. f
&nbsp; &nbsp; &nbsp; &nbsp; 逻辑运算符:&& || !
# d$ x$ d$ {( M3 S% `6 G&nbsp; &nbsp; &nbsp; &nbsp; 关系运算符:< > <= >=
/ u1 ^0 {2 T' x4 r6 H6 D& |&nbsp; &nbsp; &nbsp; &nbsp; 等式运算符:== != (不管x、z,结果可能是不定值)/ R* l  A# o4 {/ ]: D
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; === !==(对参数的x、z都进行比较)' d, W: a% J( c3 r, l
&nbsp; &nbsp; &nbsp; &nbsp; 移位运算符:<< >>
( J: j5 q' [7 L&nbsp; &nbsp; &nbsp; &nbsp; 位拼接运算符:{ },将几个信号拼接起来,例如{a,b[3:0],w,3'b100}" h4 v) k. {' u# r7 y( E
&nbsp; &nbsp; &nbsp; &nbsp; 缩减运算符:C =&B;C =|B;C =^B;
' x8 Z( g6 Z+ C+ x( p- ^&nbsp; &nbsp; &nbsp; &nbsp; 优先级别:和c语言差不多,加括号
: w. _. m# A2 o# g7 t  ?' c&nbsp; &nbsp; 赋值语句:" S2 N- Z- L" ]0 D. [
&nbsp; &nbsp; &nbsp; &nbsp; 1)非阻塞赋值方式(b <= a)
4 c8 Q7 t1 x( i5 p. j" D&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.块结束才完成赋值( ]6 h7 R* _( J: n: n4 W
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.b的值不是立刻就改变的
, Q1 L8 I$ S; J, w3 W&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c.在可综合的模块中常用
1 |  C  _" b- ]9 s" o: e&nbsp; &nbsp; &nbsp; &nbsp; 2)阻塞赋值方式(b = a)
" Y+ M- L3 X7 H3 d&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.赋值语句执行完成后,块才结束3 `6 H. [" Y" L: }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.b的值在赋值语句执行后立刻改变
+ }* o5 A- r8 ~+ {$ `% R&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c.可能会产生意想不到的结果4 w/ o/ l2 c  k3 R2 F, ]
&nbsp; &nbsp; &nbsp; &nbsp; 简单理解:" I$ q( c7 K* I# x: K, F
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 非阻塞赋值用了多个触发器,每次时钟到达,所有触发器都触发一次7 l+ J  [* J9 k: q4 t+ m& M- ?& n
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 阻塞赋值连到同一个触发器上,时钟到达,导致所有寄存器被赋值. Z$ n# W/ E: O1 p6 f/ @/ u+ N/ c
---------------------

4 V& `5 T4 J) ?) B& o
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-7-28 08:08 , Processed in 0.109375 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表