我正在尝试使用进位先行加法器制作乘法器。但我的输出有一半是zzzz。这是我的代码的一部分。 cla16 是一个 16 位进位超前加法器。它在 v16bit 模块的输出处生成 zz。
module v16bit(a,b,p);
input [15:0] a,b;
output [31:0] p;
wire [15:0] p1,p2,p3,p4;
wire [17:0] s1,s2;
v8bit adabudi(a[7:0],b[7:0],p1);
v8bit sjubh(a[15:8],b[7:0],p2);
v8bit csfc(a[7:0],b[15:8],p3);
v8bit cucbu(a[15:8],b[15:8],p4);
assign p[7:0]= p1[7:0];
csa16bit bubsuf(p2,p3,{8'b0,p1[15:8]},s1);
assign p[15:8]=s1[7:0];
// cla16 consn(p4, s1[17:8],s2);
cla16 consn(p4, {6'b0,s1[17:8]},s2); //////{THIS PART IS PRODUCING ZZZ AT OUTPUT}
assign p[31:16]=s2[15:0];
endmodule
module cla16(a,b, cin, sum);
input [15:0] a,b;
input cin;
output [15:0] sum;
//output cout;
wire c1,c2,c3,c4;
cla4 cla1 ( a[3:0] , b[3:0], 1'b0, sum[3:0] , c1) ;
cla4 cla2 ( a[7:4] , b[7:4], c1, sum[7:4] , c2) ;
cla4 cla3( a[11:8] , b[11:8], c2, sum[11:8] , c3) ;
cla4 cla6( a[15:12] , b[15:12], c3, sum[15:12] , c4) ;
endmodule
module cla4(a,b, cin, sum,cout);
input [3:0] a,b;
input cin;
output [3:0] sum;
output cout;
wire [3:0] p,g,c;
assign p=a^b;//propagate
assign g=a&b; //generate
//carry=gi + Pi.ci
assign c[0]=cin;
assign c[1]= g[0]|(p[0]&c[0]);
assign c[2]= g[1] | (p[1]&g[0]) | p[1]&p[0]&c[0];
assign c[3]= g[2] | (p[2]&g[1]) | p[2]&p[1]&g[0] | p[2]&p[1]&p[0]&c[0];
assign cout= g[3] | (p[3]&g[2]) | p[3]&p[2]&g[1] | p[3]&p[2]&p[1]&g[0] | p[3]&p[2]&p[1]&p[0]&c[0];
assign sum=p^c;
endmodule
我不明白为什么输出端显示高阻抗。如果您发现任何错误,请帮助我。
您的代码在该行上有端口连接错误。您的模拟器应该将此报告为编译警告;检查你的日志文件。如果没有,请考虑使用不同的模拟器,例如 edaplayground 上的模拟器。
cla16
模块有 4 个端口,但您仅在 consn
实例中连接到其中 3 个端口。
您使用了按顺序连接。这意味着
s2
连接到 cin
的 input
cla16
端口。您将 s2
声明为电线,这意味着它的默认值为 z
。由于您将其连接到输入端口,因此它未被驱动,这意味着在整个模拟过程中它保持在 z
。