题目:Create a 100-bit binary adder. The adder adds two 100-bit numbers and a carry-in to produce a 100-bit sum and carry out.
解题:
module top_module(
input [99:0] a, b,
input cin,
output cout,
output [99:0] sum );
wire [99:0]cc;
assign sum[0] = a[0]^b[0]^cin;
assign cc[0] = a[0]&b[0] | b[0]&cin | a[0]&cin;
integer i=1;
always@(*)begin
for(i=1;i<100;i++)begin
sum[i] = a[i]^b[i]^cc[i-1];
cc[i] = a[i]&b[i] | b[i]&cc[i-1] | a[i]&cc[i-1];
end
end
assign cout=cc[99];
endmodule
解题正确: