47 lines
946 B
C#
47 lines
946 B
C#
using System;
|
|
namespace hwo.bitworks
|
|
{
|
|
public class ADD : MultipleBitsSource
|
|
{
|
|
|
|
XOR xor2,xor3;
|
|
AND and12,andC;
|
|
OR or;
|
|
|
|
public ADD(LogicBase source1,LogicBase source2,LogicBase carry)
|
|
{
|
|
and12 = new AND(source1,source2);
|
|
xor2 = new XOR(source1,source2);
|
|
andC = new AND(carry,xor2);
|
|
or = new OR(andC,and12);
|
|
|
|
xor3 = new XOR(source1,source2,carry);
|
|
}
|
|
|
|
public override bool bitValue(int bit)
|
|
{
|
|
switch (bit){
|
|
case 1:
|
|
return or.value();
|
|
case 0:
|
|
return xor3.value();
|
|
default:
|
|
throw new IndexOutOfRangeException(String.Format("ADD supplies 2 bits, but bit #{0} requested",bit));
|
|
}
|
|
}
|
|
|
|
public override identity.BitIdentity getBitIdentity(int bit)
|
|
{
|
|
switch (bit){
|
|
case 1:
|
|
return or.identity();
|
|
case 0:
|
|
return xor3.identity();
|
|
default:
|
|
throw new IndexOutOfRangeException(String.Format("ADD supplies 2 bits, but bit #{0} requested",bit));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|