FullAdder constructor

FullAdder({
  1. required Logic a,
  2. required 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({
  required Logic a,
  required Logic b,
  required Logic carryIn,
  super.name = 'full_adder',
}) {
  a = addInput('a', a, width: a.width);
  b = addInput('b', b, width: b.width);
  carryIn = addInput('carry_in', carryIn, width: carryIn.width);

  final carryOut = addOutput('carry_out');
  final sum = addOutput('sum');

  final and1 = carryIn & (a ^ b);
  final and2 = b & a;

  sum <= (a ^ b) ^ carryIn;
  carryOut <= and1 | and2;
}