【问题标题】:Syntax error: invalid module item when declaring variables语法错误:声明变量时模块项无效
【发布时间】:2021-11-14 06:01:34
【问题描述】:
module fourbitadder(a,b,carry,s,outcar);
input [3,0]a,b;
input carry;
output  [3,0]s;
output outcar;     
wire c_1,c_2,c_3,c_4;
wire [3,0]p;                                    //error is here
fulladder fa1(a[0],b[0],carry,p[0],c_1);
fulladder fa2(a[1],b[1],c_1,p[1],c_2);          //error is here
fulladder fa3(a[2],b[2],c_2,p[2],c_3);
fulladder fa4(a[3],b[3],c_3,p[3],c_4);
assign s=p;
assign outcar = c_4;
endmodule 

syntax error
 error: invalid module item.
syntax error
 error: invalid module item.

【问题讨论】:

    标签: verilog


    【解决方案1】:

    线或寄存器的宽度声明为[MSB:LSB] 而不是[MSB,LSB]

    module fourbitadder (
            a,
            b,
            carry,
            s,
            outcar
    );
    
        input [3:0] a, b;
        input carry;
        output [3:0] s;
        output outcar;
    
        wire c_1, c_2, c_3, c_4;
        wire [3:0] p;
    
        fulladder fa1(a[0],b[0],carry,p[0],c_1);
        fulladder fa2(a[1],b[1],c_1,p[1],c_2);
        fulladder fa3(a[2],b[2],c_2,p[2],c_3);
        fulladder fa4(a[3],b[3],c_3,p[3],c_4);
    
        assign s = p;
        assign outcar = c_4;
    
    endmodule
    

    【讨论】:

      【解决方案2】:

      您似乎正在使用iverilog 作为模拟器。有时您可以通过其他模拟器获得更多有用的错误消息。如果您在注册免费帐户时在edaplayground 上编译代码,就会出现这种情况。例如,使用 Cadence 模拟器,我们得到:

      input [3,0]a,b;
              |
      xmvlog: *E,SVEXTK (testbench.sv,2|8): expecting a ':' or ']' (following the first expression in a packed/unpacked dimension).
      
      output  [3,0]s;
                |
      xmvlog: *E,SVEXTK (testbench.sv,4|10): expecting a ':' or ']' (following the first expression in a packed/unpacked dimension).
      
      wire [3,0]p;                                    //error is here
             |
      xmvlog: *E,SVEXTK (testbench.sv,7|7): expecting a ':' or ']' (following the first expression in a packed/unpacked dimension).
      

      让工具准确地告诉你问题出在哪里会好得多:在所有向量范围内用分号替换逗号。

        input [3:0]a,b;
        input carry;
        output  [3:0]s;
        output outcar;     
        wire c_1,c_2,c_3,c_4;
        wire [3:0]p;         
      

      【讨论】:

        猜你喜欢
        • 2014-09-22
        • 1970-01-01
        • 1970-01-01
        • 2014-02-23
        • 1970-01-01
        • 1970-01-01
        • 2020-04-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多