2

我为连接编写了如下代码,但显示错误:

module main ;  
 bit [4:0] a;  
 reg b,c,d;  
 initial  
 begin  
    b = 0;  
    c = 1;  
    d = 1;  
    a = {b,c,0,0,d};  
    {b,c,d} = 3'b111;  
    $display(" a %b b %b c %b d %b ",a,b,c,d);  
 end  
endmodule  

这里的错误表明constants cannot be concatenated.

它不能在这里连接零和一。谁能帮我解决这个问题?

4

3 回答 3

4

当前代码连接 32 位(或整数)宽度 0。你真正想要的是:

a = {b, c, 1'b0, 1'b0, d};  

注意:通过节奏工具,我得到:

file: main.sv
    a = {b,c,0,0,d};  
             |
ncvlog: *E,NONOWD (main.sv,11|13): Illegal use of a constant without an explicit width specification [4.1.14(IEEE)].
    a = {b,c,0,0,d};  
               |
ncvlog: *E,NONOWD (main.sv,11|15): Illegal use of a constant without an explicit width specification [4.1.14(IEEE)].
于 2013-07-30T08:10:49.913 回答
2

请参阅IEEE 1800-2012 LRM的 11.4.12 连接运算符

串联中不允许使用大小不一的常数。这是因为需要连接中每个操作数的大小来计算连接的完整大小。

所以这是一种非法使用。您必须明确指定常数的位大小。

于 2013-07-30T08:49:48.220 回答
1

由于错误表明无法连接常量,因此您在这里尝试连接非法的常量值。明确提及每个值的位大小将解决您的问题。下面是代码:

module concat;
  bit [4:0] a;
  reg b,c,d;
  initial
  begin
    b=1'b0;
    c=1'b1;
    d=1'b1;
    a={b,c,1'b0,1'b0,d};
    {b,c,d}=3'b111;
    $display("a: %b, b: %b, c: %b, d: %b",a,b,c,d);
  end
endmodule
于 2016-03-13T16:27:32.723 回答