首页 > 解决方案 > 由于方向声明导致编译代码错误

问题描述

我正在使用iverilog以下方式从互联网上运行代码:

例子.v

 module example
      (A,B,C,D,E,F,Y);
wire t1, t2, t3, Y;

nand #1 G1 (t1,A,B);
and  #2 G2 (t2,C,~B,D);
nor  #1 G3 (t3,E,F);
nand #1 G4 (Y,t1,t2,t3);
endmodule

和示例-test.v

 module testbench;
 reg A,B,C,D,E,F; wire Y;
 example DUT(A,B,C,D,E,F,Y);

 initial
 begin
  $monitor ($time," A=%b, B=%b, C=%b, D=%b, E=%b, F=%b, Y=%b", A,B,C,D,E,F,Y);
  #5 A=1; B=0; C=0; D=1; E=0; F=0;
  #5 A=0; B=0; C=1; D=1; E=0; F=0;
  #5 A=1; C=0; D=1; 
  #5 F=1;
  #5 $finish;
  end
 endmodule

我使用以下命令编译它

 iverilog -o mysim example.v example-test.v

并得到以下错误:

 example.v:1: error: Port A (1) of module example has no direction declaration.
 example.v:1: error: Port B (2) of module example has no direction declaration.
 example.v:1: error: Port C (3) of module example has no direction declaration.
 example.v:1: error: Port D (4) of module example has no direction declaration.
 example.v:1: error: Port E (5) of module example has no direction declaration.
 example.v:1: error: Port F (6) of module example has no direction declaration.
 example.v:1: error: Port Y (7) of module example has no direction declaration.
 example.v:2: error: signal A in module testbench.DUT is not a port.
 example.v:2:      : Are you missing an input/output/inout declaration?
 example.v:2: error: signal B in module testbench.DUT is not a port.
 example.v:2:      : Are you missing an input/output/inout declaration?

代码中的整个 Verilog 语法是否example.v不正确/已过时?为什么我收到编译错误?

示例取自 youtube nptel verilog 教程

标签: verilogiverilog

解决方案


该消息告诉您,您需要在 module 中使用方向关键字声明所有模块端口,例如inputand 。这修复了错误:outputexample

module example
      (A,B,C,D,E,F,Y);
      input A,B,C,D,E,F;
      output Y;
wire t1, t2, t3;

nand #1 G1 (t1,A,B);
and  #2 G2 (t2,C,~B,D);
nor  #1 G3 (t3,E,F);
nand #1 G4 (Y,t1,t2,t3);
endmodule

视频大约 28 分钟后,example代码是正确的,因为它使用inputoutput. 您复制的代码稍后会显示在视频中,并且不正确。

请注意,不需要也声明Ywire.


避免重复端口名称的更简洁方法如下:

module example (
    input A,B,C,D,E,F,
    output Y
);
wire t1, t2, t3;

nand #1 G1 (t1,A,B);
and  #2 G2 (t2,C,~B,D);
nor  #1 G3 (t3,E,F);
nand #1 G4 (Y,t1,t2,t3);
endmodule

推荐阅读