Verilog语法+:的说明
“+:”、"-:"语法
看到这个语法的时候是在分析AXI lite 总线源码时碰见的,然后查阅了资料,做出如下解释。
1.用处
这两个应该算是运算符,运用在多位的变量中,如下:
slv_reg0[(byte_index8) +: 8] <= S_AXI_WDATA[(byte_index8) +: 8];
2."+:"
变量[起始地址 +: 数据位宽] <–等价于–> 变量[(起始地址+数据位宽-1):起始地址]
data[0 +: 8] <--等价于--> data[7:0]
data[15 +: 2] <--等价于--> data[16:15]
1
2
3."-:"
变量[结束地址 -: 数据位宽] <–等价于–> 变量[结束地址:(结束地址-数据位宽+1)]
data[7 -: 8] <--等价于--> data[7:0]
data[15 -: 2] <--等价于--> data[15:14]
1
2
End
相关语法为自己的理解,如有不对的地方,请大家留言讨论
————————————————
版权声明:本文为CSDN博主「我看唔人生」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/feiliantong/article/details/107782129
一 主题: +:语法说明
语法背景等等先来一遍(算是前言吧)
写在前面的话
这个小小的语法这几天把我搞得头疼 今天集中说明一下 这个小问题 也是做个记录 留着以后查看
参考Verilog-2001语法规范
先官宣一下:
Bit-selects extract a particular bit from a vector net, vector reg, integer variable, or time variable. The bit can be addressed using an expression. If the bit-select is out of the address bounds or the bit-select is x or z, then the value returned by the reference shall be x. The bit-select or part-select of a variable declared as real or realtime shall be considered illegal.
Several contiguous bits in a vector net, vector reg, integer variable, or time variable can be addressed and are known as part-selects. There are two types of part-selects, a constant part-select and an indexed part-select.
A constant part-select of a vector reg or net is given with the following syntax:
vect[msb_expr:lsb_expr] 例如: vect[31:0]
Both expressions shall be constant expressions. The first expression has to address a more significant bit than the second expression. If the part-select is out of the address bounds or the part-select is x or z, then the value returned by the reference shall be x.
An indexed part select of a vector net, vector reg, integer variable, or time variable is given with the following syntax:
reg [15:0] big_vect;
reg [0:15] little_vect;
big_vect[lsb_base_expr +: width_expr]
little_vect[msb_base_expr +: width_expr]
big_vect[msb_base_expr -: width_expr]
little_vect[lsb_base_expr -: width_expr]
The width_expr shall be a constant expression. It also shall not be affected by run-time parameter assignments. The lsb_base_expr and msb_base_expr can vary at run-time. The first two examples select bits starting at the base and ascending the bit range. The number of bits selected is equal to the width expression. The second two examples select bits starting at the base and descending the bit range. Part-selects that address a range of bits that are completely out of the address bounds of the net, reg, integer, or time, or when the part-select is x or z, shall yield the value x when read, and shall have no effect on the data stored when written.
Part-selects that are partially out of range shall when read return x for the bits that are out of range, and
when written shall only affect the bits that are in range.
Examples:
reg [31:0] big_vect;
reg [0:31] little_vect;
reg [63:0] dword;
integer sel;
The first four if statements show the identity between the two part select constructs. The last one shows an
indexable nature.
initial begin
if ( big_vect[0 +:8] == big_vect[7 : 0]) begin end
if (little_vect[0 +:8] == little_vect[0 : 7]) begin end
if ( big_vect[15 -:8] == big_vect[15 : 8]) begin end
if (little_vect[15 -:8] == little_vect[8 :15]) begin end
if (sel >0 && sel < 8) dword[8sel +:8] = big_vect[7:0];
// Replace the byte selected.*
没有看懂的继续,看懂的撤吧,,,,,,,
大概总结了一下,小小的语法咱们也来个三步走战略,是不是高大上吗哈哈哈哈哈
1 先看定义的变量是大端还是小端模式
reg [31:0] big_vect;
reg [0:31] little_vect;
1
2
2 看升序(+:)还是降序(-:)
3 看位宽并进行转换
举例说明:
reg [31:0] big_vect;
reg [0:31] little_vect;
问题:
big_vect[0 +:8]
little_vect[0 +:8]
1
2
3
4
5
6
7
8
9
看完了上面的战略,现在开始小试牛刀吧,解决上面的问题
首先查看变量big_vect的大小端,记住一点,转化后的与原来的大小端是一样的定义方式
reg [31:0] big_vect;为大端,那么转化后的也一定是大端,**形式不变**
big_vect[0 +:8]转化后一定是 big_vect[较大的数值 **:** 较小的数值]
little_vect[0 +:8] 转化后一定是 little_vect[较小的数值 **:** 较大的数值]
1
2
3
其次,看升序(+:)还是降序(-:)
最后, 看位宽,进行转换
big_vect [0 +: 8] 从0 开始,升序,位宽为8 ======》》》》》big_vect [7 :0]
little_vect [0 +: 8] 从0 开始,升序,位宽为8 ======》》》》》little_vect [0 :7]
big_vect [15 -: 8] 从15开始,降序,位宽为8 ======》》》》》big_vect [15 :8]
little_vect [15 -: 8] 从15开始,降序,位宽为8 ======》》》》》little_vect [8:15]
1
2
3
4
送点福利,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
再举个例子;在实际项目中遇到的:
output reg [767:0] s_axi_tx_tdata,
genvar i;
generate
for(i=0;i<24;i=i+1)
begin : TDATA_GEN
always @ ( posedge aurora_lclk or negedge rst_n )
begin
if( rst_n == 1'b0 )
s_axi_tx_tdata[i*32+:32] <= #U_DLY i;
else if({s_axi_tx_tvalid,s_axi_tx_tready,s_axi_tx_tlast} == 3'b110)
s_axi_tx_tdata[i*32+:32] <= #U_DLY s_axi_tx_tdata[i*32+:32] + 32'h18;
else if({s_axi_tx_tvalid,s_axi_tx_tready,s_axi_tx_tlast} == 3'b111)
s_axi_tx_tdata[i*32+:32] <= #U_DLY s_axi_tx_tdata[i*32+:32] + 32'd16;
else;
end
end
endgenerate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
咱们还是三步走吧!!!
1,找定义
s_axi_tx_tdata的定义形式output reg [767:0] s_axi_tx_tdata,
大端形式(其实管他干个毛呀)要求形式一样就可以了的
1
2
2,升序还是降序
s_axi_tx_tdata[i*32+:32]为升序
1
3,看位宽进行转换
s_axi_tx_tdata[i*32+:32]**形式**为s_axi_tx_tdata[较大的数值****:****较小的数值],**升序**,**位宽**为32**且**从i*32开始
当i=0时,s_axi_tx_tdata[i*32+:32] **转化** s_axi_tx_tdata[31:0]
当i=1时,s_axi_tx_tdata[i*32+:32] **转化** s_axi_tx_tdata[63:32]
当i=2时,s_axi_tx_tdata[i*32+:32] **转化** s_axi_tx_tdata[95:64]
1
2
3
4
5
6
-----------------------------------------------------------------------------------------------------------------------------------------
## **当i时,s_axi_tx_tdata[i*32+:32] **转化** s_axi_tx_tdata[i*32+32-1:i*32]**
如果时降序呢
类似:s_axi_tx_tdata[i*32-:32]
1
2
3
4
5
6
大总结 来点大字
够直接了吧 到此为止!!!!!!!!!
有错请联系。。。。365654859@qq.com或者留言
————————————————
版权声明:本文为CSDN博主「相顾无言@相忘江湖」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40994893/article/details/103487821
Verilog语法+:的说明的更多相关文章
- Verilog语法基础讲解之参数化设计
Verilog语法基础讲解之参数化设计 在Verilog语法中,可以实现参数化设计.所谓参数化设计,就是在一个功能模块中,对于一个常量,其值在不同的应用场合需要设置为不同的置,则将此值在设计时使用 ...
- verilog语法实例学习(4)
Verilog模块 Verilog中代码描述的电路叫模块,模块具有以下的结构: module module_name[ (portname {, portname})]; //端口列表 [parame ...
- verilog语法实例学习(1)
本文档中通过verilog实例来学习verilog语法.Verilog是一种硬件描述语言,它具有并发性和时序性.并发性是指不同硬件模块的同时操作,时序性是指信号的赋值或操作在时钟的边沿进行.由于作者本 ...
- verilog语法学习目录
verilog语法实例学习(1) Verilog中的注释 Verilog中的信号 标识符 信号的值 Verilog中的数字 Verilog中的参数 verilog语法实例学习(2) 线网类型 变量类型 ...
- 跟着我从零开始入门FPGA(一周入门XXOO系列)-1、Verilog语法
(本连载共七部分,这是第一部分) 作者:McuPlayer2013 (EETOP FPGA版块版主) 原帖地址:http://bbs.eetop.cn/thread-385362-1-1.html ...
- verilog语法实例学习(12)
verilog中的综合和不可综合总结 Verilog中综合的概念 综合就是EDA工具或者说综合工具把我们编写的verilog代码转化成具体电路的过程.Verilog中有很多语法,结构,过程,语句,有些 ...
- verilog语法实例学习(6)
函数和任务 函数 https://wenku.baidu.com/view/d31d1ba8dd3383c4bb4cd283.html verilog中函数的目的是允许代码写成模块的方式而不是定义独立 ...
- verilog语法实例学习(5)
子电路模块 子电路模块的使用 一个verilog模块能够作为一个子电路包含在另一个模块中.采用这种方式,所有的模块都必须定义在一个文件中,那么verilog编译器就必须被告知每个模块的所属.模块例化的 ...
- verilog语法实例学习(2)
Verilog中的信号类型 线网类型 线网类型表示一个或多个门或者其它类型的信号源驱动的硬件连线.如果没有驱动源,则线网的默认值为z.verilog中定义的线网类型有以下几种: wire,tr ...
- Verilog语法
语法子集很小,易用. 模块:module…endmodule 端口:input,output,inout(双向特殊) inout比较难用,有一张真值表,需要大家观察后书写,基本原则就是输入时一定是高阻 ...
随机推荐
- 在回显时遇到的问题,回显的值无法显示到页面 vue
//理解为 重新渲染 this.form的数据 1 this.form = Object.assign({}, this.form)
- ESXI密码正确无法登录
场景描述: 今天新安装了一个VMware ESXi 6.5的系统,密码仍然用的习惯采用的密码.但在使用中,无论是使用vSphere Client连接,还是在vCenter Server中添加这台ESX ...
- 【情景题】NPDP经典题目(下)
1.员工Mary是ACE电气公司的产品经理,公司高管要求她准备一份评价标准清单,从而以该清单为基础来对该产品组合中的新机会进行评价.她提交的清单如下:-潜在市场份额-对公司获利能力的潜在贡献-产品开发 ...
- 添加vscode到windows的右键菜单
保存为bat Windows Registry Editor Version 5.00 ; Open files [HKEY_CLASSES_ROOT\*\shell\Open with VS Cod ...
- C++的switch/case,需要大括号
如果,switch/case的某一条case语句包含初始化定义变量,例如int i. 那么case后面的语句,需要用大括号包装起来. 原因如下: https://stackoverflow.com/q ...
- GFS预报数据下载
#更新#2019年6月12日之后,gfs预报场存放的目录变了,需要修改.get_gfs.pl第51行改为 $URL='https://nomads.ncep.noaa.gov/pub/data/ncc ...
- 分治-1-归并排序(Divide and Conquer-1-merge sort)
#include <stdio.h> #define INFINITY 999999 #define LEN(A) ((sizeof (A)) / (sizeof A[0])) void ...
- 接口设置ip跨域
// 允许跨域请求的地址'allowUrls' => [ 'http://localhost:8080', 'http://192.168.2.224', 'http://192.168.2.2 ...
- Spring UnitTest
demo:https://files.cnblogs.com/files/netact/spring01.zip 首先说一下Spring IOC的运行机制,同过xml或者annotation()来将p ...
- .net基础—多线程(二)
Thread 在.NET中最早提供的控制线程类型的类型:System.Threading.Thread类.使用该类型可以直观地创建.控制和结束线程.下面是一个简单的多线程程序: static void ...