【问题标题】:How can I run this code without syntax error?如何在没有语法错误的情况下运行此代码?
【发布时间】:2022-01-18 14:11:46
【问题描述】:

当我在 cmd 上运行这段代码时,它给了我一个语法错误。有什么帮助吗?

module xor (a, b, c); 
 input a, b; 
 output c; 
 wire c, not_a, not_b; 
   not a_invert (not_a, a); 
   not b_invert (not_b, b); 
   and A1 (x, not_a, b); 
   and A2 (y, not_b, a); 
   or Result (c, x, y); 
endmodule 

module xor_test(a, b); //test bench
   input a, b;
   wire c;
   xor x(a,b,c);
   initial
   begin
      $monitor("c=%b",c);
   end
endmodule

module main();
   wire a=0, b=1 ; 
   xor_test t1(a,b);
endmodule

【问题讨论】:

  • حبيبة أحمد 您是否阅读了有关在获得有助于解决问题的答案时该怎么做的链接?

标签: module verilog xor bitwise-xor


【解决方案1】:

您收到语法错误,因为您尝试使用 xor 作为模块名称。由于xor是Verilog中的保留关键字,因此将其用作模块名称是非法的。您可以将其重命名为 xor1:

module xor1 (a, b, c); ////////// CHANGED
 input a, b; 
 output c; 
 wire c, not_a, not_b; 
   not a_invert (not_a, a); 
   not b_invert (not_b, b); 
   and A1 (x, not_a, b); 
   and A2 (y, not_b, a); 
   or Result (c, x, y); 
endmodule 

module xor_test(a, b); //test bench
   input a, b;
   wire c;
   xor1 x(a,b,c);  ////////// CHANGED
   initial
   begin
      $monitor("c=%b",c);
   end
endmodule

module main();
   wire a=0, b=1 ; 
   xor_test t1(a,b);
endmodule

我用注释 CHANGED 更改了 2 行。

xor 是门类型,就像代码中的 orandnot 一样。请参阅 IEEE Std 1800-2017,第 28 节。门级和开关级建模

这是edaplayground上的一个运行示例

【讨论】:

    猜你喜欢
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-02
    相关资源
    最近更新 更多