系统Verilog:用于零件索引的电线输入

我有以下代码:

module rotate
(
input wire [5:0]       index,// tells how many bits to rotate
input [31:0]      a,output [31:0]     b
);

我想为左旋转实现此assign语句:

assign b  = {a[32-index-1 : 0],a[31: 32-index] ;

..
..
..

endmodule

由于在仿真期间会评估导线/逻辑信号,因此上述分配将不起作用。我无法使用参数。

我尝试将导线转换为整数,然后进行赋值,但仍然无法正常工作。

int i1 = index ;
assign assign b[i1] = a[i1] ; // this worked
assign b[i1-1 : 0] = a[i1-1 : 0] ; //not worked

我在always_comb内使用for循环实现,但我想要一种更简单的方法,例如串联操作等。

请以适当的方式提供帮助。

cbleong1 回答:系统Verilog:用于零件索引的电线输入

  

我想使用串联运算符进行旋转操作,旋转计数将由输入指定。

您非常亲密,尤其是使用两个串联的a时。您所要做的就是使用+:运算符:

wire [63:0] a_twice = {a,a}; 
assign b = a_twice[ index +: 32]; 

The +: operator gives you the bits from index to index+31:
3322222222221111111111          3322222222221111111111
1098765432109876543210987654321010987654321098765432109876543210
           <-------------  +32  ----------> index=21
本文链接:https://www.f2er.com/3082318.html

大家都在问