当前位置:网站首页>第六章 数据流建模
第六章 数据流建模
2022-07-01 23:21:00 【江南小作坊】
连续赋值
连续赋值语句是verilog数据流建模的基本语句,用于对线网进行赋值。
这玩意等价门级描述,却是从更高的抽象角度描述电路。
连续赋值语句必须以关键词
assign
开始。连续赋值语句有以下几种特点:
- 左边的值必须是一个标量 / 向量线网 / 标量与向量线网的拼接,这三种里面选一个,它不能是向量或向量寄存器。
- 总是激活状态,只要任意一个操作数发生变化,表达式立即重新计算,重新赋值。
- 操作数可以是标量 / 向量的线网或寄存器 / 函数调用。
- 赋值延迟可以用于控制对线网赋予新值的时间,类似门延迟。
举例
//out是线网,in1, in2也是线网 assign out = in1 & in2; // addr是16位向量线网 // addr1_bits, addr2_bits都是16位向量寄存器 assgin addr[15:0] = addr1_bits[15:0] ^ addr2_bits[15:0]; // 拼接 assign { c_out, sum[3:0]} = a[3:0] + b[3:0] + c_in;
隐式连续赋值
看到这个隐字,就晓得了,肯定缺了什么。
在线网声明的同时,对其进行赋值。线网只能被声明一次,因此隐式连续赋值只能有一次。
// 普通赋值 wire out; assgin out = in1 & in2; // 可等价于 wire out = in1 & in2;
隐式线网声明
同理,既然可以隐掉
assgin
,那可以隐掉wire
吗?当然也是可以的
// out并未对其做线网声明,仿真器会推断出out是隐式声明的线网 wire in1,in2; assgin out = in1 & in2;
延迟
- 连续赋值语句中的延迟,用于控制任一操作数发生变化到语句左值被赋予新值之间的时间间隔(说白了就是,左边的值什么时候发生变化,这个时间是可以人为定义的)。
- 指定赋值延迟的方法:
- 普通赋值延迟
- 隐式连续赋值延迟
- 线网声明延迟
普通赋值的延迟
- 在连续赋值语句中说明延迟的值,延迟值位于
assgin
后面。assgin #10 out = in1 & in2;
- 惯性延迟:在上面的例子中,
in1 & in2
的新值,赋值给左边之前,有10个时间单位的延迟,如果在这10个时间单位内,in1 & in2
的值又发生了变化,赋值表达式的新值回取in1 & in2
的当前值。这种性质就是惯性延迟。 - 如图所示,小于延迟时间的信号被屏蔽掉了,因为刚打算过10个时间单位赋值1给out,结果in1自己变为0了,因此out为0。可以用来屏蔽时间较短的脉冲信号。
隐式连续赋值的延迟
- 同理,概念是一样的,只是赋值方式变了而已。
// 隐式连续赋值 wire #10 out = in1 & in2; // 等效于 wire out; assign #10 out = in1 & in2;
线网声明的延迟
- 同理,概念是一样的
// 线网延迟 wire #10 out; assgin out = in1 & in2; // 等效于 wire out; assign #10 out = in1 & in2;
表达式
数据流建模使用表达式来描述设计。表达式、操作符和操作数是数据流建模的基础。
表达式:由操作符和操作数构成,目的是根据操作符的意义计算出一个结果。
a ^ b addr[20:17] + addr[20:17] in1 | in2
操作数:操作数可以是定义的任何数据类型,
操作符:对操作数进行运算产生一个结果。
操作符类型
- 有以下几种类型的操作符:算术、逻辑、关系、等价、按位、缩减、移位、拼接与条件操作符。
- 挑几个不熟悉的记录下
等价操作符
- 相关说明如图
缩减操作符
- 只有一个操作符,对向量操作数逐位进行操作,产生一个一位的结果。
条件操作符
带有三个操作数,用法:
condition_expr ? true_expr : false_expr;
即:计算条件表达式,如果为真,则计算
true_expr
;为假,计算false_expr
;为不确定x,则两个表达式都计算,然后两个结果逐位比较。如果相等,则结果中该位的值为操作数中该位的值;如果不想等,则结果中该位的值为x。条件表达式类似多路选择器
注意:if-else可以替换条件表达式,但是只能在块语句中,不能在连续赋值语句中替换。
优先级
- 建议用小括号将各个表达式分开。
举例
四选一多路选择器
- 如下图,这是前面学习的门级建模描述
- 使用逻辑方程描述
- 使用条件操作符
- 可见,使用数据流的建模方式是非常简便的。
四位全加器
- 同理,用数据流操作语句来描述一个四位全加器
脉动进位计数器
总结
边栏推荐
- CKS CKA ckad change terminal to remote desktop
- 2021 RoboCom 世界机器人开发者大赛-高职组初赛
- Daily three questions 6.30 (2)
- Istio, ebpf and rsocket Broker: in depth study of service grid
- Li Kou today's question -241 Design priorities for operational expressions
- 【微服务|Sentinel】sentinel整合openfeign
- 2021 RoboCom 世界机器人开发者大赛-高职组复赛
- 神经网络物联网的未来趋势与发展
- SQL optimization
- What is the difference between memory leak and memory overflow?
猜你喜欢
物联网现状及未来发展趋势
[applet] realize the left and right [sliding] list through the scroll view component
Redis RDB快照
Paramètres communs de matplotlib
软件架构的本质
2022安全员-C证考试题模拟考试题库及模拟考试
认识--Matplotlib
CKS CKA ckad change terminal to remote desktop
Practical application and extension of plain framework
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
随机推荐
Zero foundation tutorial of Internet of things development
Three development trends of enterprise application from the perspective of the third technological revolution
想请教股票开户要认识谁?在线开户是安全么?
Behind sharing e-commerce: the spirit of CO creation, symbiosis, sharing, CO prosperity and win-win
JS - use of arguments
Wechat personal small store one click opening assistant applet development
RPA: Bank digitalization, business process automation "a small step", and loan review efficiency "a big step"
What are the common types of points mall games?
深度学习 | 三个概念:Epoch, Batch, Iteration
Commemorate becoming the first dayus200 tripartite demo contributor
Linux基础 —— CentOS7 离线安装 MySQL
Why is PHP called hypertext preprocessor
小程序表单校验封装
认识--Matplotlib
Notes to problems - file /usr/share/mysql/charsets/readme from install of mysql-server-5.1.73-1 glibc23.x86_ 64 c
Who do you want to know when opening a stock account? Is it safe to open an account online?
The online beggar function of Japanese shopping websites
Concepts of dictionary, hash table and array
URL introduction
转行软件测试,知道这四点就够了!