在 Verilog 中制作全加器

Making a full adder in Verilog

我正在尝试在 Verilog 中制作一个加法器,但到目前为止我还没有成功,我想知道是否有人可以提供帮助。 这是我的代码:

module fulladder.v(
input a,
input b,
input c,
output sum,
output carry
);
wire (w1, w2, w3, w4);
xor(sum, a, w2);
xor(w2, b, c);
and (w3, b, c);
and (w4, b, c);
and (w5, c, a);
or (carry, w3, w4, w5);
endmodule

当我 运行 它与 fulladder.v 在模块之后我得到一个语法错误但是当我使用 fulladder(没有.v)时我得到很多错误:

***** START RUN *****
ERROR:HDLCompiler:806 - "fulladder.v" Line 8: Syntax error near "w1".
ERROR:HDLCompiler:1059 - "fulladder.v" Line 8: w1 is an unknown type
WARNING:HDLCompiler:329 - "fulladder.v" Line 10: Target <w2> of concurrent assignment or output port connection should be a net type.
WARNING:HDLCompiler:329 - "fulladder.v" Line 11: Target <w3> of concurrent assignment or output port connection should be a net type.
WARNING:HDLCompiler:329 - "fulladder.v" Line 12: Target <w4> of concurrent assignment or output port connection should be a net type.
ERROR:HDLCompiler:598 - "fulladder.v" Line 1: Module <fulladder> ignored due to previous errors.
***** OUTPUT *****
***** RESULT *****
FAIL

有谁知道这是怎么回事?非常感谢任何帮助!

谢谢

正确的语法是

wire w1, w2, w3, w4;

此外,您从不使用 w1,您使用 w5 但未声明它。

在 Verilog 中创建全加器并不是一项艰巨的任务。 绝对必须删除 fulladder.v。试试下面的代码。

module fulladder(A,B,Cin,Sum,Cout);   
input A,B,Cin;
output Sum,Cout;
wire andout1, andout2, xorout;
xor(xorout,A,B);
xor(Sum,xorout,Cin);
and(andout1,Cin,xorout);
and(andout2,A,B);
or(Cout,andout1,andout2);
endmodule

了解更多详细信息,以及您是否想知道如何为全加器编写测试平台。按照下面的 link。那里有几篇关于 Verilog 编码的博客文章。

Design a Full Adder with Verilog

module FA(
A,
B,
CarryIn,
Sum,
CarryOut);
input A;
input B;
input CarryIn;
output Sum;
output CarryOut;

wire w_WRITE_1;
wire w_WRITE_2;
wire w_WRITE_3;

assign w_WRITE_1=A ^ B;
assign w_WRITE_2=w_WRITE_1 & CarryIn;
assign w_WRITE_3=A & B;
assign Sum=w_WRITE_1 ^ CarryIn;
assign CarryOut=w_WRITE_2 | w_WRITE_3;

endmodule