一 主题: +:语法说明

语法背景等等先来一遍(算是前言吧)

写在前面的话
这个小小的语法这几天把我搞得头疼 今天集中说明一下 这个小问题 也是做个记录 留着以后查看
参考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[8
sel +:8] = big_vect[7:0];
// Replace the byte selected.*

没有看懂的继续,看懂的撤吧,,,,,,,

大概总结了一下,小小的语法咱们也来个三步走战略,是不是高大上吗哈哈哈哈哈

1 先看定义的变量是大端还是小端模式

     reg [31:0] big_vect;reg [0:31] little_vect;

2 看升序(+:)还是降序(-:)

3 看位宽并进行转换

举例说明:
reg [31:0] big_vect;
reg [0:31] little_vect;问题:
big_vect[0 +:8]
little_vect[0 +:8]

看完了上面的战略,现在开始小试牛刀吧,解决上面的问题

首先查看变量big_vect的大小端,记住一点,转化后的与原来的大小端是一样的定义方式

reg [31:0] big_vect;为大端,那么转化后的也一定是大端,**形式不变**
big_vect[0 +:8]转化后一定是       big_vect[较大的数值     **:**   较小的数值]
little_vect[0 +:8] 转化后一定是    little_vect[较小的数值    **:**     较大的数值]

其次,看升序(+:)还是降序(-:)

最后, 看位宽,进行转换

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]

送点福利,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
再举个例子;在实际项目中遇到的:
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 )
beginif( 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,找定义

s_axi_tx_tdata的定义形式output  reg     [767:0]             s_axi_tx_tdata,
大端形式(其实管他干个毛呀)要求形式一样就可以了的

2,升序还是降序

s_axi_tx_tdata[i*32+:32]为升序

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]

-----------------------------------------------------------------------------------------------------------------------------------------

## **当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]

大总结 来点大字


够直接了吧 到此为止!!!!!!!!!

有错请联系。。。。365654859@qq.com或者留言

Verilog语法+:的说明相关推荐

  1. [转]verilog语法学习心得

    verilog语法学习心得 1.数字电路基础知识: 布尔代数.门级电路的内部晶体管结构.组合逻辑电路分析与设计.触发器.时序逻辑电路分析与设计 2.数字系统的构成: 传感器  AD  数字处理器  D ...

  2. Verilog 语法入门知识

    Verilog 语法入门知识 一.变量类型 ①数值 数值表示采用 <二进制位数>'<数值表示的进制><数值>的结构. 其中进制可以为b.o.d.h分别代表二.八.十 ...

  3. Verilog语法-005—宏定义

    Verilog语法-005-宏定义 1.Verilog宏定义-`ifdef `ifndef `ifdef FOR_FPGA //如果定义了FOR_FPGA宏,则会执行如下 语句/或者没有语句 `els ...

  4. 【系统设计】Verilog语法及示例(2)

    参考Verilog语法 | 教程 (ustc.edu.cn) 1.7 D触发器 D触发器是一个具有记忆功能.具有两个稳定状态的信息存储器件,是构成时序逻辑的最基本逻辑单元.其具有两个稳定状态,即&qu ...

  5. verilog语法学习目录

    verilog语法实例学习(1) Verilog中注释 Verilog代码中的信号 标识符 信号的值 Verilog中的数字 Verilog中的参数 verilog语法实例学习(2) 线网类型 变量类 ...

  6. Verilog语法之运算符

    本文转自知乎罗成的文章Verilog语法之四:运算符 总的文章小白如何快速入门Verilog Verilog HDL语言的运算符范围很广,其运算符按其功能可分为以下几类: 算术运算符(+,-,×,/, ...

  7. Verilog语法和典型电路

    这里写目录标题 Verilog语法知识 Q:锁存器 Q:D触发器 Q:消除毛刺 Q:同步复位和异步复位 Q:边沿检测 Q:握手信号 Q:脉冲展宽(单bit慢采快) Q:二进制与格雷码的转换 Q:二进制 ...

  8. Verilog语法之变量

    本文转自知乎罗成的Verilog语法之三:变量 总的文章链接地址小白如何快速入门Verilog 本文首发于微信公众号"花蚂蚁",想要学习FPGA及Verilog的同学可以关注一下. ...

  9. verilog语法中+:和-:用法

    verilog语法中+:和-:主要用来进行位选择. 位选择从向量net.向量 reg.整数变量或时间变量中提取特定位.可以使用表达式寻址该位.如果位选择超出地址边界或位选择为 x 或 z,则引用返回的 ...

  10. Verilog 语法(二)···············简单入门

    经过数字逻辑电路课程的学习,大家已对多路选择器(数据选择器)有了一定的认识.本节将通过建模2选1的数据选择器,简单介绍Verilog的各级建模语言. 一.行为级建模 使用always块来对数据选择器进 ...

最新文章

  1. 再见 JDK ...
  2. SAP UI5 debug mode
  3. Jerry本地安装SAP Kyma的一些失败尝试
  4. 软件工程—团队作业1
  5. 不止 JavaScript 与 React,前端程序员必备的 9 大技能!
  6. Cookie工具类的借鉴别人的ThinkGem的代码学习
  7. Java 通过递归求解汉诺塔问题 源码 经典递归问题讲解
  8. ORA-01075: you are currently logged on
  9. 漫谈 Clustering (追忆篇): Regularized GMM
  10. 阿里云存储:做深基础,助力新基建 | 凌云时刻
  11. mac虚拟摄像头插件_macOS平台下虚拟摄像头的研发总结
  12. Wangle源码分析:Service
  13. Matlab随机森林库
  14. android 关于屏幕截屏的几种办法
  15. [运算放大器]佛朗哥笔记 - 有源滤波器I - KRC滤波器
  16. unity3d,跟着大佬做自己的第一个游戏(第一步,游戏模型制作)
  17. oracle spa性能测试,SPA for 11g 分析性能
  18. IDEA实现单元测试
  19. 奥运来了,有些常用药在药店买不到。
  20. 插件 - 收藏集 - 掘金

热门文章

  1. 敲开bp神经网络之门(三,机器视觉斑点blob匹配中使用)
  2. C++在使用fgetc读取文件时出现方框乱码
  3. 开机提示:one of your disks needs to be checked解决方法
  4. 统计一个字符串中大写字母,小写字母,以及数字的个数。
  5. OSChina 周一乱弹 ——程序员已经习惯熬夜了吧
  6. 华为路由器交换机eNSP配置命令
  7. 解决Linux图片加水印(Graphics2D)出现方框的问题
  8. Zotero安装配置插件教程: 多端同步、自动翻译、抓取题录信息、参考文献等
  9. 扫地机器人的技术升级之路 自主规划清扫成主流
  10. 【win32】Helloworld