Verilog-2001的向量部分选择

以下转载地址:http://www.cnblogs.com/jyaray/archive/2011/11/28/2266082.html


rt,什么是向量部分选择呢?

verilog-2001 LRM中有这么一句话:

对于a[8*i+:8],this is the so-called "Indexed vector part selects" 。

在Verilog-1995中,可以选择向量的任一位输出,也可以选择向量的连续几位输出,不过此时连续几位的始末数值的index需要是常量。

vect[msb_expr : lsb_expr]; //其中msb_expr和lsb_expr必须是常量表达式。

而在Verilog-2001中,可以用变量作为index,进行part select。

[base_expr +: width_expr] //positive offset

[base_expr -: width_expr] //negative offset

其中base_expr可以是变量,而width_expr必须是常量。+:表示由base_expr向上增长width_expr位,-:表示由base_expr向下递减width_expr位。

例如:

reg [63:0] word;

reg [3:0] byte_num; //a value from 0 to 7

wire [7:0] byteN = word[byte_num*8 +: 8];

如果byte_num的值为4,则将word[39:32]赋值给byteN。


以下转载地址:Verilog-2001新增特性(实例分析)

http://bbs.ednchina.com/BLOG_ARTICLE_190233.HTM

Indexed vector part selects


在Verilog-1995中,可以选择向量的任一位输出,也可以选择向量的连续几位输出,不过此时连续几位的始末数值的index需要是常量。而在Verilog-2001中,可以用变量作为index,进行part select。


[base_expr+:width_expr] //positive offset

[base_expr-:width_expr] //negative offset


       其中base_expr可以是变量,而width_expr必须是常量。+:表示由base_expr向上增长width_expr位,-:表示由base_expr向上递减width_expr位。例如:


reg [63:0] word;

reg [3:0] byte_num; //a value from 0 to 7

wire [7:0] byteN =word[byte_num*8 +: 8];

如果byte_num的值为4,则word[39:32]赋值给byteN。


多维数组


Verilog-1995只允许一维数组,而Verilog-2001允许多维数组。

//1-dimensional array of 8-bit reg variables

//(allowed in Verilog-1995 and Verilog-2001)


reg [7:0] array1 [0:255];

wire [7:0] out1 = array1[address];


//3-dimensional array of 8-bit wire nets

//(new for Verilog-2001)


wire [7:0]array3 [0:255][0:255][0:15];

wire [7:0] out3 =array3[addr1][addr2][addr3];


而且在Verilog-1995中不能对一维数组中取出其中的一位,比如要取出上面array1[7][5],需要将array1[7]赋给一个reg变量比如arrayreg <= array1[7],再从arrayreg中取出bit5,即arrayreg[5]。而在Verilog-2001中,可以任意取出多维数组中的一位或连续几位,比如:


//select the high-order byte of one word in a

//2-dimensional array of 32-bit reg variables


reg [31:0] array2 [0:255][0:15];

wire [7:0] out2 =array2[100][7][31:24];


verilog复制运算符

{n{m}}

Replicate value m, n times

  • Repetition multipliers (must be constants) can be used:
    • {3{a}} // this is equivalent to {a, a, a}
  • Nested concatenations and replication operator are possible:
    • {b, {3{c, d}}} // this is equivalent to {b, c, d, c, d, c, d}

关于for loop 的可综合性



  • 12
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值