我正在尝试在Verilog中制作一个4位全加器,但是似乎无法实例化全加器。我也无法跟踪错误。
`timescale 1 ns / 1 ps
module halfadder(input a, input b, output s, output c);
xor (s, a, b);
and (c, a, b);
endmodule
module fulladder(input cin, input a, input b, output s, output c);
wire c1, s1, c2;
halfadder (a, b, s1, c1);
halfadder (cin, s1, s, c2);
or (c, c1, c2);
endmodule
module bitadder(input cin, input [3:0] a, input [3:0] b, output [3:0] s, output c);
wire c0,c1,c2;
fulladder (cin, a[0], b[0], s[0], c0);
fulladder (c0, a[1], b[1], s[1], c1);
fulladder (c1, a[2], b[2], s[2], c2);
fulladder (c2, a[3], b[3], s[3], c);
endmodule
答案 0 :(得分:2)
您需要为所有模块的实例添加实例名称:Halfadder和fulladder。
module fulladder(input cin, input a, input b, output s, output c);
wire c1, s1, c2;
halfadder ha0 (a, b, s1, c1);
halfadder ha1 (cin, s1, s, c2);
or (c, c1, c2);
endmodule
module bitadder(input cin, input [3:0] a, input [3:0] b, output [3:0] s, output c);
wire c0,c1,c2;
fulladder fa0 (cin, a[0], b[0], s[0], c0);
fulladder fa1 (c0, a[1], b[1], s[1], c1);
fulladder fa2 (c1, a[2], b[2], s[2], c2);
fulladder fa3 (c2, a[3], b[3], s[3], c);
endmodule
基元(异或等)的实例名称是可选的。