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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

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

" m9 D) B% O1 E6 b+ M. z8 ?4 t6 f. s$ L% r: F
+ f. n( a5 A7 \" {* j* G$ O7 i9 g
    常量:
5 Z. V$ R$ |6 n/ T6 Y/ E&nbsp; &nbsp; &nbsp; &nbsp; 整数:<位宽 num'><进制 b|o|d|h><数字>,例如 4'b1010- v4 V3 c  A  a
&nbsp; &nbsp; &nbsp; &nbsp; x值(不定值)和z值(高阻值,也可用?代替)7 c( h8 q0 M4 b5 Q2 h) a) I
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x和z可以标识某一位或者某一个数字: s4 w* O3 k- p, ^
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4'b10x0,4'bx,4'b101z,4'bz,4'b?5 K7 B/ [. E8 d8 G
&nbsp; &nbsp; &nbsp; &nbsp; 负数:整数最前面加-/ N: v; b  U, P4 ~( Y5 W3 }
&nbsp; &nbsp; &nbsp; &nbsp; 下划线:分割数字部分,更加易读(8'b1000_1000)
' ~0 T# M7 y7 c2 ?7 v&nbsp; &nbsp; 参数:parameter* `; [. q+ T9 C; Q2 s/ S
&nbsp; &nbsp; &nbsp; &nbsp; parameter 参数名=表达式;- R- H* E9 ?: I, ]9 L
&nbsp; &nbsp; &nbsp; &nbsp; 表达式只能是数字或者定义过的参数
! ^+ |! Q8 ]! u8 s+ |&nbsp; &nbsp; 变量:2 [  z; ^, F, C4 o
&nbsp; &nbsp; &nbsp; &nbsp; wire型:wire [n-1:0] 数据名;5 K. S* N! a7 o8 f0 }8 p, C4 W
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wire表示信号,常用来表示assign关键字指定的组合逻辑信号
5 M. n) }9 a* j&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wire型信号可以用作输入,输出3 g  w& \5 a. [7 _3 [
&nbsp; &nbsp; &nbsp; &nbsp; reg型:reg [n-1:0] 数据名;# x  D; m" B7 x
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 对存储单元的抽象
) a" e- @" Y8 F&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 常用来表示always模块内的指定信号,常代表触发器
' ]. B4 _: H3 J; j, M9 c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; always块内被赋值的每一个信号都必须定义为reg型* d& |$ Z. a' @
&nbsp; &nbsp; &nbsp; &nbsp; memory型:reg [n-1:0] 存储器名[m-1:0];+ Z+ I. m# `* S5 n6 H
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reg [n-1:0]表示基本存储单元的大小3 ]0 q- D# N% U5 t. l* f6 @
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 存储器名[m-1:0]表示基本存储单元的个数,存储空间的容量
: [! J- }" h* {( U&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 对存储器进行地址索引的表达式必须是常数表达式2 v4 \, x4 L' q5 S) A7 |% u9 ]9 ^
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 一个n位寄存器可以在一条赋值语句里进行赋值,而一个完整的存储器不行
( @+ P8 I6 u, r$ O1 w&nbsp; &nbsp; 运算符及表达式:
+ f6 E6 _4 N* a5 E( K% F&nbsp; &nbsp; &nbsp; &nbsp; 基本运算符:+ - * / %
) B2 j* d. F. K9 L+ b' A&nbsp; &nbsp; &nbsp; &nbsp; 位运算符:~ & | ^ ^~
/ w5 t7 f9 o5 e& X: r&nbsp; &nbsp; &nbsp; &nbsp; 逻辑运算符:&& || !& X# ~( O4 X1 Y1 d) U: g
&nbsp; &nbsp; &nbsp; &nbsp; 关系运算符:< > <= >=
3 K, s9 F$ y, e! D4 l&nbsp; &nbsp; &nbsp; &nbsp; 等式运算符:== != (不管x、z,结果可能是不定值)- t& J3 z$ ]0 o5 E
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; === !==(对参数的x、z都进行比较)) _9 ]$ J: ?# i$ B" l( T
&nbsp; &nbsp; &nbsp; &nbsp; 移位运算符:<< >>
, o" ~: o, c2 O* z8 \3 e/ \&nbsp; &nbsp; &nbsp; &nbsp; 位拼接运算符:{ },将几个信号拼接起来,例如{a,b[3:0],w,3'b100}
3 J: Y" F' E# U' s  {% E5 N&nbsp; &nbsp; &nbsp; &nbsp; 缩减运算符:C =&B;C =|B;C =^B;" X, x" ]8 b$ k+ V
&nbsp; &nbsp; &nbsp; &nbsp; 优先级别:和c语言差不多,加括号
: C& ?9 T' f3 _6 G6 i&nbsp; &nbsp; 赋值语句:
# j8 r; p, ?/ X4 \/ Z&nbsp; &nbsp; &nbsp; &nbsp; 1)非阻塞赋值方式(b <= a)- L3 H+ H, y$ B# M4 k- ~' W
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.块结束才完成赋值3 Z+ w% S4 Z0 s
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.b的值不是立刻就改变的! F# E7 Z2 ^" r2 R/ K5 e" `
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c.在可综合的模块中常用
( K; I# E1 O. d&nbsp; &nbsp; &nbsp; &nbsp; 2)阻塞赋值方式(b = a), @; S/ N: }3 I& s" V
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.赋值语句执行完成后,块才结束
9 L2 M+ c  p, ~+ W6 b5 C&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.b的值在赋值语句执行后立刻改变
% u5 {  b6 w: T* D3 \&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c.可能会产生意想不到的结果
" I3 z' }! W' @. V&nbsp; &nbsp; &nbsp; &nbsp; 简单理解:- d/ ]! {  J' H, |# r$ F; w& F+ p
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 非阻塞赋值用了多个触发器,每次时钟到达,所有触发器都触发一次
) ~* a% b1 W9 q&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 阻塞赋值连到同一个触发器上,时钟到达,导致所有寄存器被赋值8 o8 R- ^( Q5 v( R
---------------------

9 f/ ?+ N+ [4 e3 ~6 j0 q" \, }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-7-28 19:56 , Processed in 0.125000 second(s), 24 queries , Gzip On.

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

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

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