FullAdder constructor

FullAdder(
  1. Logic a,
  2. Logic b, {
  3. required Logic? carryIn,
  4. String name = 'full_adder',
})

Constructs a FullAdder with value a, b and carryIn based on full adder truth table.

Implementation

FullAdder(
  super.a,
  super.b, {
  required super.carryIn,
  super.name = 'full_adder',
}) {
  if ((a.width != 1) | (b.width != 1) | ((carryIn ?? Const(0)).width != 1)) {
    throw RohdHclException('widths must all be one');
  }
  if (carryIn == null) {
    throw RohdHclException('FullAdder must have a carryIn input');
  }
  sum <= [carryIn! & (a ^ b) | a & b, (a ^ b) ^ carryIn!].swizzle();
}