Logic Verilog测试台输出为16位进位加法器上的x和z

Logic Verilog测试台输出为16位进位加法器上的x和z,logic,verilog,hdl,iverilog,Logic,Verilog,Hdl,Iverilog,我一直在尝试复制一个16位加法器,但在我的测试台上似乎没有得到任何结果。有线索吗 module adder(a,b,c,s,cout); input a,b,c; output s,cout; xor #1 g1(w1,a,b), g2(s,w1,c); and #1 g3(w2,c,b), g4(w3,c,a), g5(w4,a,b); or #1 g6(cout,w2,w3,w4); endmodule module sixteenbitAdder(x,y,s,cout,cin); in

我一直在尝试复制一个16位加法器,但在我的测试台上似乎没有得到任何结果。有线索吗

module adder(a,b,c,s,cout);
input a,b,c;
output s,cout;
xor #1
g1(w1,a,b),
g2(s,w1,c);
and #1
g3(w2,c,b),
g4(w3,c,a),
g5(w4,a,b);
or #1
g6(cout,w2,w3,w4);
endmodule


module sixteenbitAdder(x,y,s,cout,cin);
input [15:0] x,y;
output [15:0] s;
input cin;
output cout;
wire [15:0] c;
 adder f0 (x[0],y[0],cin,s[0],c[0]);
 adder f1 (x[1],y[1],c[0],s[0],c[1]);
 adder f2 (x[2],y[2],c[1],s[2],c[2]);
 adder f3 (x[3],y[3],c[2],s[3],c[3]);
 adder f4 (x[4],y[4],c[3],s[4],c[4]);
 adder f5 (x[5],y[5],c[4],s[5],c[5]);
 adder f6 (x[6],y[6],c[5],s[6],c[6]);
 adder f7 (x[7],y[7],c[6],s[7],c[7]);
 adder f8 (x[8],y[8],c[7],s[8],c[8]);
 adder f9 (x[9],y[9],c[8],s[9],c[9]);
 adder f10 (x[10],y[10],c[9],s[10],c[10]);
 adder f11 (x[11],y[11],c[10],s[11],c[11]);
 adder f12 (x[12],y[12],c[11],s[12],c[12]);
 adder f13 (x[13],y[13],c[12],s[13],c[13]);
 adder f14 (x[14],y[14],c[13],s[14],c[14]);
 adder f15 (x[15],y[15],c[14],s[15],cout);
endmodule
这是我的测试台。我不知道这有多不对

module test();
wire [15:0] x,y,s;
wire cin, cout;
 testAdder testt (x,y,s,cout,cin);
 sixteenbitAdder adderr (x,y,s,cout,cin);
endmodule


module testAdder(a,b,s,cout,cin);
input [15:0] s;
input cout;
output [15:0] a,b;
output cin;
reg [15:0] a,b;
reg cin;
initial
    begin
     $monitor($time,,"a=%d, b=%d, cin=%b, s=%d, cout=%b",a,b,cin,s,cout);
     $display($time,,"a=%d, b=%d, cin=%b, s=%d, cout=%b",a,b,cin,s,cout);
     #50  a=1; b=2; cin=0; 
    end
endmodule

这就是我得到的回报

                   0 a=    x, b=    x, cin=x, s=    z, cout=z
                   0 a=    x, b=    x, cin=x, s=    X, cout=x
                  50 a=    1, b=    2, cin=0, s=    X, cout=x
                  52 a=    1, b=    2, cin=0, s=    X, cout=0
                  53 a=    1, b=    2, cin=0, s=    X, cout=0
                  55 a=    1, b=    2, cin=0, s=    Z, cout=0

你的设计有缺陷。更改:

 adder f1 (x[1],y[1],c[0],s[0],c[1]);
致:

产出:

           0 a=    x, b=    x, cin=x, s=    x, cout=x
          50 a=    1, b=    2, cin=0, s=    x, cout=x
          52 a=    1, b=    2, cin=0, s=    X, cout=0
          53 a=    1, b=    2, cin=0, s=    X, cout=0
          55 a=    1, b=    2, cin=0, s=    3, cout=0

不需要
$display

           0 a=    x, b=    x, cin=x, s=    x, cout=x
          50 a=    1, b=    2, cin=0, s=    x, cout=x
          52 a=    1, b=    2, cin=0, s=    X, cout=0
          53 a=    1, b=    2, cin=0, s=    X, cout=0
          55 a=    1, b=    2, cin=0, s=    3, cout=0