public static Bit2 Add(bool a, bool b, bool c) { var xorAb = Gates.Xor(a, b); var xorAbc = Gates.Xor(xorAb, c); var and = Gates.And(xorAb, c); var andAb = Gates.And(a, b); return(new Bit2(Gates.Or(and, andAb), xorAbc)); }
public void OrTest() { IEnumerable <bool> inputA; IEnumerable <bool> inputB; IEnumerable <bool> expected; IEnumerable <bool> actual; inputA = new bool[] { false, true, false, true }; inputB = new bool[] { false, false, true, true }; expected = new bool[] { false, true, true, true }; actual = Gates.Or(inputA, inputB); Assert.IsTrue(expected.SequenceEqual(actual)); }
/// <summary> /// Bit 15 of the input indicates the kind of instruction: /// Bit 15 | Instruction kind /// -------+----------------- /// 0 | data /// 1 | computation /// /// For a data instruction, W(data word) should reflect the input, the a flag should be 1 and all other flags should be 0. /// For a computation instruction, the ci(computation instruction) flag should be 1, W should be 0. All other flags should be mapped from the bits in the input as follows: /// Input Output /// Bit Group flag /// 14 (ignored) - /// 13 (ignored) - /// 12 source sm /// 11 computation zx /// 10 computation nx /// 9 computation zy /// 8 computation ny /// 7 computation f /// 6 computation no /// 5 destination a /// 4 destination d /// 3 destination* a /// 2 condition gt /// 1 condition eq /// 0 condition lt /// </summary> /// <param name="instruction"></param> /// <returns></returns> public static DecodedInstruction Decode(Byte2 instruction) { var isNegative = Arithmetics.IsLessThanZero(instruction); var inverted = Gates.Invert(isNegative); var s = Select16.Do(inverted, new Byte2(0), instruction); var instructionOrZero = Select16.Do(isNegative, new Byte2(0), instruction); return(new DecodedInstruction(isNegative, s.Twelve, new Operation(s.Eleven, s.Ten, s.Nine, s.Eight, s.Seven, s.Six), new Destination(Gates.Or(inverted, s.Five), s.Four, s.Three), new Condition(s.Two, s.One, s.Zero), instructionOrZero)); }
public static bool Evaluate(Condition condition, Byte2 data) { var isLessThanZero = Arithmetics.IsLessThanZero(data); var andIsLessThanZero = Gates.And(condition.LessThanZero, isLessThanZero); var equalsZero = Arithmetics.EqualsZero(data); var andIsEqualToZero = Gates.And(condition.EqualToZero, equalsZero); var isGreaterThanZero = Gates.And(condition.GreaterThanZero, Gates.And(Gates.Invert(isLessThanZero), Gates.Invert(equalsZero))); var lessOrEqual = Gates.Or(andIsLessThanZero, andIsEqualToZero); var lessOrEqualOrGreater = Gates.Or(lessOrEqual, isGreaterThanZero); return(lessOrEqualOrGreater); }
public void False_false_should_return_false() { var res = Gates.Or(false, false); res.Should().BeFalse(); }
public void True_true_should_return_true() { var res = Gates.Or(true, true); res.Should().BeTrue(); }
public static bool EqualsZero(Bit2 a) { var orA = Gates.Or(a.High, a.Low); return(Gates.Invert(orA)); }