/***************************** add.lib *****************************/ component { in opd1, opd2 } halfAdder { out sum, carry } begin { in opd1 opd2 } xor( 2 ) { out sum }; { in opd1 opd2 } and( 2 ) { out carry }; end component { in opd1, opd2, carryIn } fullAdder { out sum, carryOut } begin path sum1, carry1, carry2; { in opd1, opd2 } halfAdder { out sum1, carry1 }; { in sum1, carryIn } halfAdder { out sum, carry2 }; { in carry1 carry2 } or( 2 ) { out carryOut }; end component { in opd1[ n ], opd2[ n ], carryIn } add( n ) { out sum[ n ], carryOut } begin path carry[ n + 1 ]; { in carryIn } join( 1 ) { out carry[ 0 ] }; for i from 0 upto n do { in opd1[ i ], opd2[ i ], carry[ i ] } fullAdder { out sum[ i ], carry[ i + 1 ] }; end { in carry[ n ] } join( 1 ) { out carryOut }; end