module f_add(a,b,cin,sum,count);
input a,b,cin;
output sum,count;
wire s1,t1,t2,t3;
xor
ux1(s1,a,b),
ux2(sum,s1,cin);
and
ua1(t3,a,b),
ua2(t2,b,cin),
ua3(t1,a,cin);
or
uo1(count,t1,t2,t3);
endmodule
module four_f_add(fa,fb,fcin,fsum,fcount);
parameter size=4;
input [size:1]fa,fb;
output[size:1]fsum;
input fcin;
output fcount;
wire [size-1:1]ftemp;
f_add
ufa1(.a(fa[1]),.b(fb[1]),.cin(fcin),.sum(fsum[1]),.count(ftemp[1])),
ufa2(.a(fa[2]),.b(fb[2]),.cin(ftemp[1]),.sum(fsum[2]),.count(ftemp[2])),
ufa3(.a(fa[3]),.b(fb[3]),.cin(ftemp[2]),.sum(fsum[3]),.count(ftemp[3])),
ufa4(fa[4],fb[4],ftemp[3],fsum[4],fcount);
endmodule