verilog - 由于方向声明导致编译代码错误
问题描述
我正在使用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 教程
解决方案
该消息告诉您,您需要在 module 中使用方向关键字声明所有模块端口,例如input
and 。这修复了错误:output
example
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
代码是正确的,因为它使用input
和output
. 您复制的代码稍后会显示在视频中,并且不正确。
请注意,不需要也声明Y
为wire
.
避免重复端口名称的更简洁方法如下:
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
推荐阅读
- hangfire - Hangfire 支持 - 支持有多好?
- python - Keras:使用 categorical_crossentropy 而不使用 one-hot 编码的目标数组
- xpath - XQuery - 优化低效查询策略(在 eXist-db 中)
- c - 当位图在 Allegro 中跟随另一个位图时闪烁
- python - 是否可以让 Kivy 应用程序窗口自动适应内部单个标签的大小?
- python - Python:使用 Facebook Graph API 在针对特定语言环境的 Facebook 页面上发布帖子
- google-assistant-sdk - 如何使用 Google Assistant SDK 完全禁用 HTML 响应?
- bash - 如何在 UNIX 中递归获取完整路径?
- c++ - 输出没有重复元素的动态数组(缩小数组)C++
- javascript - 为什么我的 Switch 语句中的 Return 语句没有按预期工作?