send me the diagram for this question..

]]>x1+x2+x3+x4+Cin1 = Sum1 + 2*(Carry1 + Cout1)

x5+x6+x7+x8+Cin2 = Sum2 + 2*(Carry2 + Cout2)

assign Cin1=0;

assign Cin2=0;

Y= ~Carry1 & ~Carry2 & ~Cout1 & ~Cout2 & (Sum1^Sum2)

The compressor is not complicated, especially with Cin equals to 0, you can search in google for more detail.

]]>looks like my always@(*) statement got a bit messed up but hopefully its clear ðŸ™‚

]]>Assuming a is my input, o is my output.

Define two buses xsb and x.

always@(*) begin

for(i=0;i<(1<=0;j=j-1)

for(j=0;i<(1<<j);i=i+1) begin

xsb[i] = (xsb[2*i] | xsb[2*i+1]) | (x[2*i]&x[2*i+1]);

x[i] = (x[2*i]&~x[2*i+1])|(~x[2*i]&x[2*i+1]);

end

o = x[0] & ~xsb[0]; //zero output if xsb[0] got set

end

y = {a[3:1], 4’b0101};

else

y = {a[3:1],4’b0000}; ]]>

Each full adder with inputs {a_n, b_n, ci_n} gives an output {co_n, s_n} which is the number of 1’s in the input, in binary. Think of s_n as indicating that there is one 1 in the input, and co_n as indicating that there are two 1’s in the input.

Now, if we sum s_n’s, we will get an answer that indicates the number of 1’s in those sums. This answer can go in the final answer in the LSB.

If we sum co_n’s, we will get an answer that indicates 2x the number of 1’s. This answer can go in the final answer, shifted left by 1 bit, to account for the 2x multiplier.

]]>what happens if either x or y is driven by a Z?

]]>