示例#1
0
文件: ALU.cs 项目: Serfati/Memory
        public override bool TestGate()
        {
            InputX.Set2sComplement(5);
            InputY.Set2sComplement(5);
            ZeroX.Value     = 1;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 0;
            NotOutput.Value = 1;
            Console.WriteLine("Case 1: " + Output.Get2sComplement());
            Console.WriteLine("Negative?: " + Negative.Value);
            Console.WriteLine("Zero?: " + Zero.Value);
            Console.WriteLine("");

            InputX.Set2sComplement(5);
            InputY.Set2sComplement(5);
            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 1;
            NotY.Value      = 1;
            F.Value         = 0;
            NotOutput.Value = 0;
            Console.WriteLine("Case 2: " + Output.Get2sComplement());
            Console.WriteLine("Negative?: " + Negative.Value);
            Console.WriteLine("Zero?: " + Zero.Value);
            Console.WriteLine("");

            InputX.SetValue(6);
            InputY.SetValue(5);

            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 1;
            NotY.Value      = 1;
            F.Value         = 0;
            NotOutput.Value = 1;
            if (Output.Get2sComplement() != -7 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            ZeroX.Value     = 1;
            ZeroY.Value     = 1;
            NotX.Value      = 0;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 0;
            if (Output.Get2sComplement() != 0 || Zero.Value != 1 || Negative.Value != 0)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public override bool TestGate()
        {
            int wordBitsFilter         = WordBitsFilter();
            var wsFlags                = new WireSet(6);
            int inputPermutationsCount = (int)Math.Pow(2, Size);
            int flagsPermutationsCount = (int)Math.Pow(2, wsFlags.Size);

            for (int i = 0; i < inputPermutationsCount; i++)
            {
                InputX.SetValue(i);
                for (int j = 0; j < inputPermutationsCount; j++)
                {
                    InputY.SetValue(j);
                    for (int k = 0; k < flagsPermutationsCount; k++)
                    {
                        wsFlags.SetValue(k);
                        SetFlags(wsFlags);
                        bool test = Test(
                            wordBitsFilter,
                            InputX.Get2sComplement(),
                            InputY.Get2sComplement(),
                            ZeroX.Value,
                            NotX.Value,
                            ZeroY.Value,
                            NotY.Value,
                            F.Value,
                            NotOutput.Value
                            );
                        if (!test)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
        private bool TestNumbers(int iX, int iY)
        {
            InputX.SetValue(iX);
            InputY.SetValue(iY);

            SetControlBits(1, 0, 1, 0, 1, 0);

            if (Output.GetValue() != 0)
            {
                return(false);
            }

            SetControlBits(1, 1, 1, 1, 1, 1);

            if (Output.GetValue() != 1)
            {
                return(false);
            }

            SetControlBits(1, 1, 1, 0, 1, 0);

            if (Output.GetValue() != -1)
            {
                return(false);
            }

            SetControlBits(0, 0, 1, 1, 0, 0);

            if (Output.GetValue() != iX)
            {
                return(false);
            }

            SetControlBits(1, 1, 0, 0, 0, 0);

            if (Output.GetValue() != iY)
            {
                return(false);
            }

            SetControlBits(0, 0, 1, 1, 0, 1);

            if (iX > 0 && Output.GetValue() != ~iX)
            {
                return(false);
            }

            SetControlBits(1, 1, 0, 0, 0, 1);

            if (iY > 0 && Output.GetValue() != ~iY)
            {
                return(false);
            }

            SetControlBits(0, 1, 1, 1, 1, 1);

            if (Output.GetValue() != iX + 1)
            {
                return(false);
            }

            SetControlBits(1, 1, 0, 1, 1, 1);

            if (Output.GetValue() != iY + 1)
            {
                return(false);
            }

            SetControlBits(0, 0, 1, 1, 1, 0);

            if (Output.GetValue() != iX - 1)
            {
                return(false);
            }

            SetControlBits(1, 1, 0, 0, 1, 0);

            if (Output.GetValue() != iY - 1)
            {
                return(false);
            }

            SetControlBits(0, 0, 0, 0, 1, 0);

            if (Output.GetValue() != iX + iY)
            {
                return(false);
            }

            SetControlBits(0, 1, 0, 0, 1, 1);

            if (Output.GetValue() != iX - iY)
            {
                return(false);
            }

            SetControlBits(0, 0, 0, 1, 1, 1);

            if (Output.GetValue() != iY - iX)
            {
                return(false);
            }

            SetControlBits(0, 0, 0, 0, 0, 0);

            if (Output.GetValue() != (iY & iX))
            {
                return(false);
            }

            SetControlBits(0, 1, 0, 1, 0, 1);

            if (Output.GetValue() != (iY | iX))
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        public override bool TestGate()
        {
            InputX.SetValue(6);
            InputY.SetValue(5);
            //setting ALU bit settings
            ZeroX.Value     = 1;
            ZeroY.Value     = 1;
            NotX.Value      = 0;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != 0 || Zero.Value != 1 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            ZeroY.Value     = 1;
            NotX.Value      = 1;
            NotY.Value      = 1;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != 1 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            ZeroY.Value     = 1;
            NotX.Value      = 1;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != -1 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            ZeroY.Value     = 1;
            NotX.Value      = 0;
            NotY.Value      = 1;
            F.Value         = 0;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != 6 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 0;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != 5 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 1;
            NotY.Value      = 1;
            F.Value         = 0;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != -7 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 0;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != -6 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 1;
            NotY.Value      = 1;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != -6 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != -5 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 1;
            ZeroY.Value     = 1;
            NotY.Value      = 1;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != 7 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 1;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != 6 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 1;
            NotY.Value      = 1;
            F.Value         = 1;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != 5 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 1;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != 4 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 0;
            //
            if (Output.Get2sComplement() != -5 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 1;
            ZeroY.Value     = 0;
            NotY.Value      = 0;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != 1 || Zero.Value != 0 || Negative.Value != 0)
            {
                return(false);
            }

            //setting ALU bit settings
            ZeroX.Value     = 0;
            NotX.Value      = 0;
            ZeroY.Value     = 0;
            NotY.Value      = 1;
            F.Value         = 1;
            NotOutput.Value = 1;
            //
            if (Output.Get2sComplement() != -1 || Zero.Value != 0 || Negative.Value != 1)
            {
                return(false);
            }

            return(true);
        }