为了账号安全,请及时绑定邮箱和手机立即绑定

什么是“ +:”和“-:”?

什么是“ +:”和“-:”?

我最近在verilog / systemverilog代码中看到了此运算符。logic [15:0] down_vect;logic [0:15] up_vect;down_vect[lsb_base_expr +: width_expr]up_vect  [msb_base_expr +: width_expr]down_vect[msb_base_expr -: width_expr]up_vect  [lsb_base_expr -: width_expr]我很少见过,所以我想问一下这是什么,何时以及如何使用它?
查看完整描述

2 回答

?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

该特定语法称为索引部分选择。当您需要从多位寄存器中的可变偏移量中选择固定数量的位时,此功能非常有用。


这是语法示例:


reg [31:0] dword;

reg [7:0] byte0;

reg [7:0] byte1;

reg [7:0] byte2;

reg [7:0] byte3;


assign byte0 = dword[0 +: 8];    // Same as dword[7:0]

assign byte1 = dword[8 +: 8];    // Same as dword[15:8]

assign byte2 = dword[16 +: 8];   // Same as dword[23:16]

assign byte3 = dword[24 +: 8];   // Same as dword[31:24]

这种语法的最大优点是可以为索引使用变量。在Verilog中选择正常部分需要常量。因此,dword[i+7:i]不允许尝试类似的方法。


因此,如果要使用变量选择来选择特定字节,则可以使用索引部分选择。


使用变量的示例:


reg [31:0] dword;

reg [7:0] byte; 

reg [1:0] i;


// This is illegal due to the variable i, even though the width is always 8 bits

assign byte = dword[(i*8)+7 : i*8];  // ** Not allowed!


// Use the indexed part select 

assign byte = dword[i*8 +: 8];


查看完整回答
反对 回复 2019-10-21
?
当年话下

TA贡献1890条经验 获得超9个赞

该运算符的用途是当您需要访问总线的一部分时,MSB位置和LSB位置都是变量,但是切片的宽度是一个常量值,如以下示例所示:


bit[7:0] bus_in = 8'hAA;

int lsb = 3;

int msb = lsb+3;  // Setting msb=6, for out bus of 4 bits


bit[3:0] bus_out_bad = bus_in[msb:lsb]; // ILLEGAL - both boundaries are variables

bit[3:0] bus_out_ok  = bus_in[lsb+:3]; // Good - only one variable


查看完整回答
反对 回复 2019-10-21
  • 2 回答
  • 0 关注
  • 884 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信