module adder6(
output[5:0] sum,
output c_out,
input[5:0] a, b,
input c_in);
wire [1:0] c_o;
adder4 a(.sum([3:0]),c_o[0],.a(a[3:0]), .b(b[3:0),c_in); //4-bits adder
full_adder fa1(sum[4],c_o[1],a[4],b[4],c_o[0]); //1-bit adder
full_adder fa2(sum[5],c_out,a[5],b[5],c_o[1]); //1-bit adder
endmodule
module adder4(
output[3:0] sum,
output c_out, // carry out
input[3:0] a, b, // operands
input c_in); // carry in
wire [2:0] c_o;
full_adder fa1(sum[0],c_o[0],a[0],b[0],c_in);
full_adder fa2(sum[1],c_o[1],a[1],b[1],c_o[0]);
full_adder fa3(sum[2],c_o[2],a[2],b[2],c_o[1]);
full_adder fa4(sum[3],c_out,a[3],b[3],c_o[2]);
endmodule
module full_adder(
output sum,
output c_out, // carry out
input a,
input b,
input c_in); // carry in
wire sum1;
wire c_in1;
wire c_out2;
half_adder ha1(sum1,c_in1,a,b);
half_adder ha2(sum,c_out2,sum1,c_in);
or(c_out,c_out2,c_in1);
endmodule
module half_adder(
output sum,
output c_out, // carry out
input a,
input b);
assign sum=a^b;
assign c_out=a&&b;
endmodule
我必须使用4位加法器和2个全加器来制作6位加法器。我确信问题出在 adder6 模块中,因为我已经分别测试了4位加法器模块,并且它可以工作。但我找不到错误。我不确定我是否在 adder4 模块中使用的 adder4 功能中建立了正确的连接。 (更新1):
module adder6_test;
// Inputs
reg [5:0] a;
reg [5:0] b;
// Outputs
wire [6:0] sum;
// Instantiate the Unit Under Test (UUT)
adder6 uut (
.sum(sum),
.a(a),
.b(b)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
a = 50;
b = 14;
#10;
a = 2;
b = 33;
#10;
a = 63;
b = 63;
end
endmodule
(更新2): 错误是: 错误:HDLCompiler:806 - “C:/Users/Iulia/Downloads/lab1_skel/ex4_skel/adder6.v”第10行:“)”附近的语法错误。
// Verilog Test Fixture Template
`timescale 1 ns / 1 ps
module TEST_gate;
reg <signal1>;
reg [2:0] <signal2>;
wire [3:0] <signal3>;
wire <signal4>;
<module_name> <instance_name> (
<port1>,
<port2>
);
integer <name1>;
integer <name2>;
// The following code initializes the Global Set Reset (GSR) and Global Three-State (GTS) nets
// Refer to the Synthesis and Simulation Design Guide for more information on this process
reg GSR;
assign glbl.GSR = GSR;
reg GTS;
assign glbl.GTS = GTS;
initial begin
GSR = 1;
GTS = 0; // GTS is not activated by default
#100; // GSR is set for 100 ns
GSR = 0;
end
// Initialize Inputs
`define auto_init
`ifdef auto_init
initial begin
end
`endif
endmodule
现在我收到这些错误: 错误:HDLCompiler:806 - “C:/Users/Iulia/Downloads/lab1_skel/ex4_skel/adder6_test.v”第6行:“&lt;”附近的语法错误。
错误:HDLCompiler:806 - “C:/Users/Iulia/Downloads/lab1_skel/ex4_skel/adder6_test.v”第7行:“&lt;”附近的语法错误。
错误:HDLCompiler:806 - “C:/Users/Iulia/Downloads/lab1_skel/ex4_skel/adder6_test.v”第8行:“&lt;”附近的语法错误。
(更新3)我修改了 adder6 模块,我设法摆脱了错误。我使用了7位求和,并且我已经消除了进位。但是现在,它没有计算总和。对于a = 63和b = 63,总和为X.这是新的adder6模块:
module adder6(
output[6:0] sum,
input[5:0] a,
input[5:0] b);
wire c_out0;
wire c_out1;
adder4 add4(sum[3:0],c_out0,a[3:0],b[3:0],c_in);
full_adder fa3(sum[4],c_out1,a[4],b[4],c_out0);
full_adder fa4(sum[5],sum[6],a[5],b[5],c_out1);
endmodule
答案 0 :(得分:1)
在adder6
声明中有这一行:
adder4 a(.sum([3:0]),c_o[0],.a(a[3:0]), .b(b[3:0),c_in); //4-bits adder
如您所见,您调用了adder4
a
的实例。与此同时,您调用了输入端口a
。这就是为什么在尝试编译代码时出现错误的原因。最简单的解决方案是重命名adder4
实例。
顺便说一下,如果工作,特定的行应该看起来有点不同:
adder4 add(.sum(sum[3:0]), .c_out(c_o[0]), .a(a[3:0]), .b(b[3:0]), .c_in(c_in));