RippleCarryAdder constructor

RippleCarryAdder(
  1. Logic a,
  2. Logic b, {
  3. Logic? carryIn,
  4. String name = 'ripple_carry_adder_carry_in',
})

Constructs an n-bit adder based on inputs List of inputs.

Implementation

RippleCarryAdder(super.a, super.b,
    {super.carryIn, super.name = 'ripple_carry_adder_carry_in'}) {
  Logic? carry;
  final sumList = <Logic>[];
  for (var i = 0; i < a.width; i++) {
    final fullAdder =
        FullAdder(a[i], b[i], carryIn: carry ?? (carryIn ?? Const(0)));

    carry = fullAdder.sum[1];
    sumList.add(fullAdder.sum[0]);
  }

  sumList.add(carry!);
  sum <= sumList.rswizzle();
}