[英]Declaring a constant with a parameterized width
I want to declare constants with a parameterized width.我想声明具有参数化宽度的常量。 For example, in this piece of code:
例如,在这段代码中:
module mux2to1 #(parameter w = 4) (output [w-1:0] O, input [w-1:0] i0, i1, input Sel);
assign O = (Sel)? i1 : i0;
endmodule
module M1 #(parameter n = 4) (input [n-1:0] A, input F, output [n+1:0] B);
mux2to1#(n+2) mux (B, XXX, XXX, F);
endmodule
In the XXXs, I would like to put all 1s for one of them, and for the other, I would like to put 0s followed by a single 1.在 XXX 中,我想为其中一个放全 1,而对于另一个,我想放 0 后跟单个 1。
How to do this?这个怎么做?
You can use the replicated concatenation operator to construct a constant:您可以使用复制的串联运算符来构造一个常量:
mux2to1 #(n+2) mux (B, {(n+2){1'b1}}, {{(n+1){1'b0}}, 1'b1}, F);
{(n+2){1'b1}}
creates a constant of n+2
1'b1
bits. {(n+2){1'b1}}
创建n+2
1'b1
位的常数。 Since n
is 4, {(n+2){1'b1}}
is the same as {6{1'b1}}
, which is the same as 6'b11_1111
.由于
n
为 4,因此{(n+2){1'b1}}
与{6{1'b1}}
相同,后者与6'b11_1111
相同。
{(n+1){1'b0}}
is the same as 5'b0_0000
, then just concatenate a single 1'b1
to that. {(n+1){1'b0}}
与5'b0_0000
相同,然后只需将单个1'b1
连接到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.