I'm making an 8-bit selectAdd8 with 4-bit Adder.
There was no complie error, but the result is just xxxxxxxx.
I guess there is some problem with my code, but I can't figure it out.
This is '8bit Select Adder Code'
module selectAdd8(
input [7:0] a,
input [7:0] b,
input cin,
output reg [7:0] sum,
output reg cout
);
reg coutL, sumL, sum0, sum1, cout0, cout1;
add4 add_lower(a[3:0],b[3:0],cin,sum,cout);
add4 add4_0(a[7:4],b[7:4],0,sum0,cout0);
add4 add4_1(a[7:4],b[7:4],1,sum1,cout1);
always @ (*)
if (coutL==1) begin
sum = {sum1, sumL};
cout = 1;
end else begin
sum = {sum0, sumL};
cout = 0;
end
endmodule
And this is 4-bit adder code. I've tested this 4-bit adder, and there was no problem.
module add4(
input [3:0] a,
input [3:0] b,
input cin,
output [3:0] sum,
output cout
);
assign {cout, sum} = a+b+cin;
endmodule
This is my test code.
When I see the result, input is okay, but cout and Sum both are just x and XXXXXXXX.
module selectAdd8_test;
// Inputs
reg [7:0] a;
reg [7:0] b;
reg cin;
// Outputs
wire [7:0] sum;
wire cout;
// Instantiate the Unit Under Test (UUT)
selectAdd8 uut (
.a(a),
.b(b),
.cin(cin),
.sum(sum),
.cout(cout)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
cin = 0;
#100;
a = 255;
b = 1;
cin = 0;
#100;
a = 135;
b = 45;
cin = 1;
#100;
a = 7;
b = 47;
cin = 0;
#100;
a = 7;
b = 28;
cin = 0;
#100;
a = 120;
b = 7;
cin = 0;
#100;
end
endmodule
