【问题标题】:Verilog Two bit Magnitude comparatorVerilog 两位幅度比较器
【发布时间】:2023-04-02 14:34:01
【问题描述】:

我试图编写一个两位比较器的 Verilog 代码,但我不断收到错误。有什么帮助吗?

错误代码:

10170 Verilog HDL syntax error at two_bitcomparatorVerilog.v(5) near text: ";"; expecting ")"

10170 Verilog HDL syntax error at two_bitcomparatorVerilog.v(7) near text: ";"; expecting ")"

10170 Verilog HDL syntax error at two_bitcomparatorVerilog.v(15) near text: "~"; expecting ")"

设计:

module twobit_comparator(

    //assigning inputs
    input wire [1:0] A, B;
    // assigning outputs
    output wire LT, GT, EQ;
    // L=Less, G=Greater, E=Equal 
    );
    
    
    wire [9:0] s;
    
    //A = B output 
    assign s0 = (~A[1] & ~A[0] & ~B[1] ~B[0]);
    assign s1 = (~A[1] & A[0] & ~B[1] & B[0]);
    assign s2 = (A[1] & ~A[0] & B[1] & ~B[0]);
    assign s3 = (A[1] & A[0] & b[1] & B[0]);
    assign EQ = s0 | s1 | s2 | s3;
    
    //A less than B output 
    assign s4 = (~A[0]) & (~A[1]) & B[0];
    assign s5 = (~A[1]) & B[1];
    assign s6 = (~A[0]) & B[1] & B[0];
    assign LT = s4 | s5| s6;
    
    // A greater than B output
    assign s7 = (~B[0]) & (~B[1]) & A[0];
    assign s8 = (~B[1]) &  A[1];
    assign s9 = (~B[0]) & A[1] & A[0];
    assign GT = s7 | s8 | s9;
    
endmodule 

【问题讨论】:

    标签: verilog comparator


    【解决方案1】:

    用逗号而不是分号分隔端口,并且不要以分号结束端口列表:

    module twobit_comparator(
    
    //assigning inputs
    input wire [1:0] A, B,
    // assigning outputs
    output wire LT, GT, EQ
    // L=Less, G=Greater, E=Equal 
    );
    

    您缺少& 运算符;我在这里添加了它:

    assign s0 = (~A[1] & ~A[0] & ~B[1] & ~B[0]);
    //                                 ^
    

    我在这里将b 更改为B(Verilog 区分大小写):

    assign s3 = (A[1] & A[0] & B[1] & B[0]);
    //                         ^
    

    通过上述更改,我不再收到任何编译错误。但是,您声明了信号s,但它没有被使用。而且,您没有声明s0s1 等,但您正在使用它们。这是因为 Verilog 允许您在 1 位宽时使用未声明的线。但是,您应该声明所有信号。例如,您可以使用:

    wire [9:0] s;
    
    assign s[0] = (~A[1] & ~A[0] & ~B[1] & ~B[0]);
    assign s[1] = (~A[1] & A[0] & ~B[1] & B[0]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 2013-08-12
      • 1970-01-01
      相关资源
      最近更新 更多