Exemplo n.º 1
0
        public ALU(int iSize)
        {
            Size      = iSize;
            InputX    = new WireSet(Size);
            InputY    = new WireSet(Size);
            ZeroX     = new Wire();
            ZeroY     = new Wire();
            NotX      = new Wire();
            NotY      = new Wire();
            F         = new Wire();
            NotOutput = new Wire();
            Negative  = new Wire();
            Zero      = new Wire();
            Output    = new WireSet(iSize);

            muxZx  = new BitwiseMux(iSize);
            muxZy  = new BitwiseMux(iSize);
            muxNx  = new BitwiseMux(iSize);
            muxNy  = new BitwiseMux(iSize);
            muxF   = new BitwiseMux(iSize);
            muxNo  = new BitwiseMux(iSize);
            notNx  = new BitwiseNotGate(iSize);
            notNy  = new BitwiseNotGate(iSize);
            notNo  = new BitwiseNotGate(iSize);
            andF   = new BitwiseAndGate(iSize);
            adderF = new MultiBitAdder(iSize);
            wireX0 = new WireSet(iSize);
            wireX0.Set2sComplement(0);
            wireY0 = new WireSet(iSize);
            wireY0.Set2sComplement(0);
            isZeroNot      = new BitwiseNotGate(iSize);
            isZeroMultiAnd = new MultiBitAndGate(iSize);

            muxZx.ConnectInput1(InputX);
            muxZx.ConnectInput2(wireX0);
            muxZx.ConnectControl(ZeroX);
            muxNx.ConnectInput1(muxZx.Output);
            notNx.ConnectInput(muxZx.Output);
            muxNx.ConnectInput2(notNx.Output);
            muxNx.ConnectControl(NotX);
            andF.ConnectInput1(muxNx.Output);
            adderF.ConnectInput1(muxNx.Output);

            muxZy.ConnectInput1(InputY);
            muxZy.ConnectInput2(wireY0);
            muxZy.ConnectControl(ZeroY);
            muxNy.ConnectInput1(muxZy.Output);
            notNy.ConnectInput(muxZy.Output);
            muxNy.ConnectInput2(notNy.Output);
            muxNy.ConnectControl(NotY);
            andF.ConnectInput2(muxNy.Output);
            adderF.ConnectInput2(muxNy.Output);
            //now from muxF
            muxF.ConnectInput1(andF.Output);
            muxF.ConnectInput2(adderF.Output);
            muxF.ConnectControl(F);
            muxNo.ConnectInput1(muxF.Output);
            notNo.ConnectInput(muxF.Output);
            muxNo.ConnectInput2(notNo.Output);
            muxNo.ConnectControl(NotOutput);
            Output.ConnectInput(muxNo.Output);
            Negative.ConnectInput(muxNo.Output[iSize - 1]);
            isZeroNot.ConnectInput(muxNo.Output);
            isZeroMultiAnd.ConnectInput(isZeroNot.Output);
            Zero.ConnectInput(isZeroMultiAnd.Output);
        }
Exemplo n.º 2
0
        public ALU(int iSize)
        {
            Size      = iSize;
            InputX    = new WireSet(Size);
            InputY    = new WireSet(Size);
            ZeroX     = new Wire();
            ZeroY     = new Wire();
            NotX      = new Wire();
            NotY      = new Wire();
            F         = new Wire();
            NotOutput = new Wire();
            Negative  = new Wire();
            Zero      = new Wire();
            Output    = new WireSet(Size);


            var fx     = new BitwiseMux(Size);
            var fAdder = new MultiBitAdder(Size);
            var fAnd   = new BitwiseAndGate(Size);

            var notX = new BitwiseNotGate(Size);
            var notY = new BitwiseNotGate(Size);

            var notCheckzero = new BitwiseNotGate(Size);
            var zeroCheck    = new MultiBitAndGate(Size);
            var nOut         = new BitwiseMux(Size);
            var notOut       = new BitwiseNotGate(Size);

            var nx = new BitwiseMux(Size);
            var ny = new BitwiseMux(Size);
            var zx = new BitwiseMux(Size);
            var zy = new BitwiseMux(Size);

            var wireX0 = new WireSet(iSize);
            var wireY0 = new WireSet(iSize);

            wireX0.Set2sComplement(0);
            wireY0.Set2sComplement(0);

            try
            {
                //zx//
                var zeroXWire = new WireSet(Size);
                zeroXWire.Set2sComplement(0);
                zx.ConnectInput1(InputX);
                zx.ConnectInput2(zeroXWire);
                zx.ConnectControl(ZeroX);
            }
            catch (Exception e)
            {
                Console.WriteLine("zx exp" + e.Message);
            }

            try
            {
                //nx//
                nx.ConnectInput1(zx.Output);
                notX.ConnectInput(zx.Output);
                nx.ConnectInput2(notX.Output);
                nx.ConnectControl(NotX);
            }
            catch (Exception e)
            {
                Console.WriteLine("nx exp" + e.Message);
            }

            try
            {
                //zy//
                var zeroYWire = new WireSet(Size);
                zeroYWire.Set2sComplement(0);
                zy.ConnectInput1(InputY);
                zy.ConnectInput2(zeroYWire);
                zy.ConnectControl(ZeroY);
            }
            catch (Exception e)
            {
                Console.WriteLine("zy exp" + e.Message);
            }

            try
            {
                //ny//
                ny.ConnectInput1(zy.Output);
                notY.ConnectInput(zy.Output);
                ny.ConnectInput2(notY.Output);
                ny.ConnectControl(NotY);
            }
            catch (Exception e)
            {
                Console.WriteLine("ny exp" + e.Message);
            }

            try
            {
                //f//
                fAdder.ConnectInput1(nx.Output);
                fAdder.ConnectInput2(ny.Output);

                fAnd.ConnectInput1(nx.Output);
                fAnd.ConnectInput2(ny.Output);

                fx.ConnectInput1(fAnd.Output);
                fx.ConnectInput2(fAdder.Output);

                fx.ConnectControl(F);
            }
            catch (Exception e)
            {
                Console.WriteLine("f exp" + e.Message);
                throw;
            }

            try
            {
                notOut.ConnectInput(fx.Output);
                nOut.ConnectInput1(fx.Output);
                nOut.ConnectInput2(notOut.Output);
                nOut.ConnectControl(NotOutput);

                /*********************************/
                Output = nOut.Output;
                /*********************************/
            }
            catch (Exception e)
            {
                Console.WriteLine("not Output exp" + e.Message);
            }

            try
            {
                //negative number check
                Negative = Output[Size - 1];

                //Zero number check
                notCheckzero.ConnectInput(nOut.Output);
                zeroCheck.ConnectInput(notCheckzero.Output);
                Zero.ConnectInput(zeroCheck.Output);
            }
            catch (Exception e)
            {
                Console.WriteLine("Output info exp" + e.Message);
                throw;
            }
        }
Exemplo n.º 3
0
        public ALU(int iSize)
        {
            Size      = iSize;
            InputX    = new WireSet(Size);
            InputY    = new WireSet(Size);
            ZeroX     = new Wire();
            ZeroY     = new Wire();
            NotX      = new Wire();
            NotY      = new Wire();
            F         = new Wire();
            NotOutput = new Wire();
            Negative  = new Wire();
            Zero      = new Wire();
            Output    = new WireSet(Size);

            zx   = new BitwiseMux(Size);
            zy   = new BitwiseMux(Size);
            nx   = new BitwiseMux(Size);
            ny   = new BitwiseMux(Size);
            fx   = new BitwiseMux(Size);
            nOut = new BitwiseMux(Size);

            notX         = new BitwiseNotGate(Size);
            notY         = new BitwiseNotGate(Size);
            notOut       = new BitwiseNotGate(Size);
            notCheckzero = new BitwiseNotGate(Size);

            fAdder = new MultiBitAdder(Size);
            fAnd   = new BitwiseAndGate(Size);

            negCheck  = new MultiBitAdder(Size);
            zeroCheck = new MultiBitAndGate(Size);

            //zx//
            WireSet zeroXWire = new WireSet(Size);

            zx.ConnectInput1(InputX);
            zx.ConnectInput2(zeroXWire);
            zx.ConnectControl(ZeroX);

            //nx//

            nx.ConnectInput1(zx.Output);
            notX.ConnectInput(zx.Output);
            nx.ConnectInput2(notX.Output);
            nx.ConnectControl(NotX);

            //zy//
            WireSet zeroYWire = new WireSet(Size);

            zy.ConnectInput1(InputY);
            zy.ConnectInput2(zeroYWire);
            zy.ConnectControl(ZeroY);

            //ny//

            ny.ConnectInput1(zy.Output);
            notY.ConnectInput(zy.Output);
            ny.ConnectInput2(notY.Output);
            ny.ConnectControl(NotY);

            //f//
            fAnd.ConnectInput1(nx.Output);
            fAnd.ConnectInput2(ny.Output);
            fAdder.ConnectInput1(nx.Output);
            fAdder.ConnectInput2(ny.Output);
            fx.ConnectInput1(fAnd.Output);
            fx.ConnectInput2(fAdder.Output);
            fx.ConnectControl(F);

            //not Outpot
            nOut.ConnectInput1(fx.Output);
            notOut.ConnectInput(fx.Output);
            nOut.ConnectInput2(notOut.Output);
            nOut.ConnectControl(NotOutput);


            Output = nOut.Output;


            //negative number check
            negCheck.ConnectInput1(nOut.Output);
            negCheck.ConnectInput2(nOut.Output);
            Negative = negCheck.Overflow;

            //Zero number check
            notCheckzero.ConnectInput(nOut.Output);
            zeroCheck.ConnectInput(notCheckzero.Output);
            Zero = zeroCheck.Output;
        }
Exemplo n.º 4
0
        //your code here

        public ALU(int iSize)
        {
            Size      = iSize;
            InputX    = new WireSet(Size);
            InputY    = new WireSet(Size);
            ZeroX     = new Wire();
            ZeroY     = new Wire();
            NotX      = new Wire();
            NotY      = new Wire();
            F         = new Wire();
            NotOutput = new Wire();
            Negative  = new Wire();
            Zero      = new Wire();


            //Create and connect all the internal components
            Output = new WireSet(Size);

            BitwiseMux m_gZX     = new BitwiseMux(Size);
            BitwiseMux m_gZY     = new BitwiseMux(Size);
            WireSet    zeroForXY = new WireSet(Size);

            zeroForXY.Set2sComplement(0);

            BitwiseNotGate m_gNotX = new BitwiseNotGate(Size); // reverse X
            BitwiseNotGate m_gNotY = new BitwiseNotGate(Size); // reverse Y
            BitwiseMux     m_gNX   = new BitwiseMux(Size);
            BitwiseMux     m_gNY   = new BitwiseMux(Size);

            BitwiseAndGate m_gBAnd = new BitwiseAndGate(Size); // X & Y
            MultiBitAdder  mbAdder = new MultiBitAdder(Size);  // X + Y

            BitwiseMux m_gF = new BitwiseMux(Size);

            BitwiseNotGate m_gNotFOut = new BitwiseNotGate(Size); // reverse F output
            BitwiseMux     m_gN       = new BitwiseMux(Size);

            MultiBitAndGate m_gZeroAnd = new MultiBitAndGate(Size);
            BitwiseNotGate  m_gZeroNot = new BitwiseNotGate(Size);


            // connect inputX and input0 to ZX, connect ZXControl
            m_gZX.ConnectInput1(InputX);
            m_gZX.ConnectInput2(zeroForXY);
            m_gZX.ConnectControl(ZeroX);

            // connect bitwiseNotXIn to ZX output, connect ZXOut to NXIn1, connect bitwiseNotOut to NXIn2
            m_gNotX.ConnectInput(m_gZX.Output);
            m_gNX.ConnectInput1(m_gZX.Output);
            m_gNX.ConnectInput2(m_gNotX.Output);
            m_gNX.ConnectControl(NotX);

            // connect inputY and input0 to ZY, connect ZYControl
            m_gZY.ConnectInput1(InputY);
            m_gZY.ConnectInput2(zeroForXY);
            m_gZY.ConnectControl(ZeroY);

            // connect bitwiseNotYIn to ZY output, connect ZYOut to NYIn1, connect bitwiseNotYOut to NYIn2
            m_gNotY.ConnectInput(m_gZY.Output);
            m_gNY.ConnectInput1(m_gZY.Output);
            m_gNY.ConnectInput2(m_gNotY.Output);
            m_gNY.ConnectControl(NotY);

            // connect NXOut to bitwiseAndIn1, connect NYOut to bitwiseAndIn2
            m_gBAnd.ConnectInput1(m_gNX.Output);
            m_gBAnd.ConnectInput2(m_gNY.Output);
            // connect NXOut to mbAdderIn1, connect NYOut to mbAdderIn2
            mbAdder.ConnectInput1(m_gNX.Output);
            mbAdder.ConnectInput2(m_gNY.Output);
            // connect bitwiseAndOut to F_In1, connect mbAdderOut to F_In2
            m_gF.ConnectInput1(m_gBAnd.Output);
            m_gF.ConnectInput2(mbAdder.Output);
            m_gF.ConnectControl(F);

            //connect F_Out to bitwiseNotFIn
            m_gNotFOut.ConnectInput(m_gF.Output);
            // connect F_Out to N_In1, connect bitwiseNotFOut to N_In2
            m_gN.ConnectInput1(m_gF.Output);
            m_gN.ConnectInput2(m_gNotFOut.Output);
            m_gN.ConnectControl(NotOutput);

            // connect N_Out to Output
            Output.ConnectInput(m_gN.Output);

            // connect negativeIndicator to last Output wire
            Negative.ConnectInput(Output[Size - 1]);
            // connect ZeroIndicator depending on zeroNot and zeroAnd concatenation
            m_gZeroNot.ConnectInput(Output);
            m_gZeroAnd.ConnectInput(m_gZeroNot.Output);
            Zero.ConnectInput(m_gZeroAnd.Output);
        }