簡體   English   中英

System Verilog:用於位零件索引的線輸入

[英]System Verilog : wire input for bits part indexing

我有以下代碼:

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

我想為左旋轉實現這個分配語句:

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

..
..
..

endmodule

上述分配將不起作用,因為線/邏輯信號是在仿真期間評估的。 我無法使用參數。

我嘗試將電線轉換為 integer 然后進行分配,仍然無法正常工作。

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 循環實現了,但我想要一個更簡單的方法,比如連接操作等。

請幫助以合適的方式。

我想使用連接運算符進行旋轉操作,旋轉計數將由輸入指定。

你非常接近,尤其是在使用兩個連接的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM