Exemple #1
0
        public static void XORWF(string commandAsString)
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(4, 7);               //Argument, Adresse f auslesen
            string dLiteralbinary = binary.Substring(3, 1);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            byte w     = Registerspeicher.W;
            byte fWert = Registerspeicher.getRegisterWert(fAsByte);

            byte result = (byte)(w ^ fWert); //W wird mit f verodert

            if (dLiteralbinary == "0")
            {
                Registerspeicher.W = result;
            }
            else if (dLiteralbinary == "1")
            {
                Registerspeicher.setRegisterWert(fAsByte, result);
            }
            else
            {
                MessageBox.Show("Problem COMF - d is not defined");
            }
            Registerspeicher.SetZeroFlag(result);
        }
Exemple #2
0
        public static void SUBWF(string commandAsString)
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(3, 7);               //Argument, Adresse f auslesen
            string dLiteralbinary = binary.Substring(2, 1);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            var fWertvar   = Registerspeicher.getRegisterWert(fAsByte);
            var w          = Registerspeicher.W;
            var resultTemp = (ushort)(fWertvar - w);
            var result     = (byte)resultTemp;

            if (dLiteralbinary == "0")
            {
                Registerspeicher.W = result;
            }
            else if (dLiteralbinary == "1")
            {
                Registerspeicher.setRegisterWert(fAsByte, result);
            }
            else
            {
                MessageBox.Show("Problem SUBWF - d is not defined");
            }
            Registerspeicher.SetZeroFlag(result);
            Registerspeicher.SetCarryFlag(resultTemp, true);
            Registerspeicher.SetDigitCarryFlag((byte)((fWertvar & 0xF) - (w & 0xF)), true);
        }
Exemple #3
0
        public static void ANDLW(string commandAsString)
        {
            byte myLiteralAsByte = ConvertStringToByte(commandAsString, 2, 2); //Argument von Befehl trennen
            byte w = Registerspeicher.W;

            Registerspeicher.W = (byte)(w & myLiteralAsByte); // Verundung Literal mit w-Register
            Registerspeicher.SetZeroFlag(Registerspeicher.W);
        }
Exemple #4
0
        public static void XORLW(string commandAsString)
        {
            byte myLiteralAsByte = ConvertStringToByte(commandAsString, 2, 2); //Argument von Befehl trennen
            byte w = Registerspeicher.W;

            Registerspeicher.W = (byte)(w ^ myLiteralAsByte); // exclusive or w mit Literal
            Registerspeicher.SetZeroFlag(Registerspeicher.W);
        }
Exemple #5
0
        public static void BSF(string commandAsString)
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(6, 7);               //Argument, Adresse f auslesen
            string bLiteralbinary = binary.Substring(3, 3);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            byte fWert = Registerspeicher.getRegisterWert(fAsByte);

            int  bAsInt = Convert.ToInt32(bLiteralbinary, 2); //B-binär wird als Int gespeichert
            byte result = 0;

            if (bAsInt == 0)
            {
                result = (byte)(fWert | 0x01);
            }
            else if (bAsInt == 1)
            {
                result = (byte)(fWert | 0x02);
            }
            else if (bAsInt == 2)
            {
                result = (byte)(fWert | 0x04);
            }
            else if (bAsInt == 3)
            {
                result = (byte)(fWert | 0x08);
            }
            else if (bAsInt == 4)
            {
                result = (byte)(fWert | 0x10);
            }
            else if (bAsInt == 5)
            {
                result = (byte)(fWert | 0x20);
            }
            else if (bAsInt == 6)
            {
                result = (byte)(fWert | 0x40);
            }
            else if (bAsInt == 7)
            {
                result = (byte)(fWert | 0x80);
            }
            else
            {
                MessageBox.Show("Problem BSF - b is not defined");
            }
            Registerspeicher.setRegisterWert(fAsByte, result);
        }
Exemple #6
0
 private static byte CheckIndirectAddressing(byte fAsByteUnchecked)
 {
     if (fAsByteUnchecked == 0x00) //wenn f = 0 hole Adresse aus FSR Register
     {
         byte FSRAdresse = Registerspeicher.getRegisterWert(Registerspeicher.FSR);
         return(FSRAdresse);
     }
     else //Ansonsten gebe das gleiche wieder zurück
     {
         return(fAsByteUnchecked);
     }
 }
Exemple #7
0
        internal static void CallRB47Interrupt()
        {
            if ((Registerspeicher.getRegisterWert(Registerspeicher.INTCON) & 0x89) == 0x89)
            {
                Stack.myStack.Push(MainWindow.CommandCounter); // und in Stack für Rücksprungadresse gespeichert
                Commands.stackAsString = MainWindow.CommandCounter.ToString("X2") + Commands.stackAsString;
                mainWin.stackBox.Text  = Commands.stackAsString;

                MainWindow.CommandCounter      = 4;
                mainWin.InterruptLabel.Content = "RB4-RB7 Interrupt";
            }
        }
Exemple #8
0
        public static void MOVWF(string commandAsString)
        {
            int    myLiteralAsNum  = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary          = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string myLiteralbinary = binary.Substring(1, 7);               //Argument, Adresse f auslesen

            int  addressToGo      = Convert.ToInt32(myLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(addressToGo);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            Registerspeicher.setRegisterWert(fAsByte, Registerspeicher.W);
        }
Exemple #9
0
        public static void SUBLW(string commandAsString)
        {
            byte myLiteralAsByte = ConvertStringToByte(commandAsString, 2, 2); //Argument von Befehl trennen

            var w          = Registerspeicher.W;
            var resultTemp = (ushort)(myLiteralAsByte - w);
            var result     = (byte)resultTemp;

            Registerspeicher.W = (byte)(myLiteralAsByte - w); // subtrahier w vom Literal
            Registerspeicher.SetZeroFlag(Registerspeicher.W);
            Registerspeicher.SetCarryFlag(resultTemp, true);
            Registerspeicher.SetDigitCarryFlag((byte)((myLiteralAsByte & 0xF) - (w & 0xF)), true);
        }
Exemple #10
0
 static void SetTimer0()
 {
     if (timerCounter == TimerValue)
     {
         tempTMRO = Registerspeicher.getRegisterWert(Registerspeicher.TMR0);
         //if (MainWindow.numberOfCycles == 2)
         //{
         //   IncreaseTimer();
         //}
         IncreaseTimer();
         timerCounter = 0;
     }
 }
Exemple #11
0
        public static void ADDLW(string commandAsString)
        {
            byte myLiteralAsByte = ConvertStringToByte(commandAsString, 2, 2); //Argument von Befehl trennen

            var w          = Registerspeicher.W;
            var resultTemp = (ushort)(myLiteralAsByte + w);
            var result     = (byte)resultTemp;

            Registerspeicher.W = (byte)(w + myLiteralAsByte); // addiere w mit Literal
            Registerspeicher.SetZeroFlag(Registerspeicher.W);
            Registerspeicher.SetCarryFlag(resultTemp);
            Registerspeicher.SetDigitCarryFlag((byte)((myLiteralAsByte & 0xF) + (w & 0xF)));
        }
Exemple #12
0
        public static void RRF(string commandAsString)                    // Carry Flag hier noch Falsch!!!!!!!!!!!!!!!!!!!!!!!!!!
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(5, 7);               //Argument, Adresse f auslesen
            string dLiteralbinary = binary.Substring(4, 1);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            ushort fWertvar = Registerspeicher.getRegisterWert(fAsByte);

            if (Registerspeicher.checkIfBitIsSet(Registerspeicher.STATUS, Registerspeicher.C))
            {
                fWertvar |= 0x100; //Linkeste Bit wird gesetzt, wenn Carrybit gesetzt war
                Console.WriteLine("fWertvar+: " + fWertvar.ToString("X2"));
            }

            if ((fWertvar & 0x01) != 0)                                                                                                       //Rechteste Bit wird ins Carryflag geschoben
            {
                Registerspeicher.speicher[Registerspeicher.STATUS]      |= 0x01;                                                              // C-flag wird auf 1 gesetzt;
                Registerspeicher.labels[Registerspeicher.STATUS].Content = Registerspeicher.speicher[Registerspeicher.STATUS].ToString("X2"); //X2 prints the string as two uppercase hexadecimal characters
                mainWin.CLabel.Content = "1";
            }
            else
            {
                Registerspeicher.speicher[Registerspeicher.STATUS]      &= 0xFE;                                                              // C-flag wird auf 0 gesetzt;
                Registerspeicher.labels[Registerspeicher.STATUS].Content = Registerspeicher.speicher[Registerspeicher.STATUS].ToString("X2"); //X2 prints the string as two uppercase hexadecimal characters
                mainWin.CLabel.Content = "0";
            }

            fWertvar >>= 1; //1 rechts schifften
            var result = (byte)fWertvar;

            if (dLiteralbinary == "0")
            {
                Registerspeicher.W = result;
            }
            else if (dLiteralbinary == "1")
            {
                Registerspeicher.setRegisterWert(fAsByte, result);
            }
            else
            {
                MessageBox.Show("Problem RRF - d is not defined");
            }
        }
Exemple #13
0
        private void ResetButton_Click(object sender, RoutedEventArgs e)
        {
            Registerspeicher.initializeRegister();
            commandCounter = 0;

            ExecutingCommandTextBlock.Text = "start over again";
            CommandNameLabel.Content       = "";
            CommandCounterLabel.Content    = commandCounter;

            Registerspeicher.W  = 0;
            TIMER0.TimerCounter = 0; //reset, auf null gesetzt

            laufzeit      = 0;
            laufzBox.Text = Convert.ToString(laufzeit);
        }
Exemple #14
0
        private static void IncreaseTimer()
        {
            if (tempTMRO == 0xFF) //wenn TMRO überläuft wird TOIF gesetzt.
            {
                tempTMRO++;
                Registerspeicher.setRegisterWert(Registerspeicher.TMR0, tempTMRO);

                //intcon wird ausgelesen und im nächsten Schritt mit 0x04 verodert, damit das TOIF (2.Bit) gesetzt wird für Interrupt
                byte tempINTCON = Registerspeicher.getRegisterWert(Registerspeicher.INTCON);
                Registerspeicher.setRegisterWert(Registerspeicher.INTCON, (byte)(tempINTCON | 0x04));
                Interrupt.CallTimerInterrupt();
            }
            else
            {
                tempTMRO++;
                Registerspeicher.setRegisterWert(Registerspeicher.TMR0, tempTMRO);
            }
        }
Exemple #15
0
        public static void SWAPF(string commandAsString)
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(5, 7);               //Argument, Adresse f auslesen
            string dLiteralbinary = binary.Substring(4, 1);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            byte fWert = Registerspeicher.getRegisterWert(fAsByte);   //Inhalt aus adresse f holen

            string fWertHex = fWert.ToString("X2");                   // als Hexwert auslesen

            string fWertA = fWertHex.Substring(0, 1);                 // Hexwert teilen
            string fWertB = fWertHex.Substring(1, 1);                 // Hexwert teilen

            string swap      = string.Concat(fWertB, fWertA);         //beide substrings in getauschter Reihenfolge zusammenfügen
            int    swapAsInt = Convert.ToInt32(swap, 16);             //zu decimal konvertieren

            string swapDec = swapAsInt.ToString("D2");

            byte result = Byte.Parse(swapDec); //string wird als byte gespeichert

            if (dLiteralbinary == "0")
            {
                Registerspeicher.W = result;
            }
            else if (dLiteralbinary == "1")
            {
                Registerspeicher.setRegisterWert(fAsByte, result);
            }
            else
            {
                MessageBox.Show("Problem SUBWF - d is not defined");
            }
        }
Exemple #16
0
        public static void INCFSZ(string commandAsString)
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(5, 7);               //Argument, Adresse f auslesen
            string dLiteralbinary = binary.Substring(4, 1);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            byte fWert = Registerspeicher.getRegisterWert(fAsByte);

            fWert++;

            if (fWert == 0)
            {
                Commands.NOP();
                MainWindow.CommandCounter++;
                MainWindow.numberOfCycles = 2;
            }
            else
            {
                if (dLiteralbinary == "0")
                {
                    Registerspeicher.W = fWert;
                }
                else if (dLiteralbinary == "1")
                {
                    Registerspeicher.setRegisterWert(fAsByte, fWert);
                }
                else
                {
                    MessageBox.Show("Problem RRF - d is not defined");
                }
            }
        }
Exemple #17
0
        public static void CheckTimer0() //Timerrate wird herausgefunden
        {
            byte InhaltOptionRegister = Registerspeicher.getRegisterWert(0x81);

            if ((InhaltOptionRegister & 0x08) == 0x08) //Watchdog: Prescaler is assigned to the WDT
            {
                if ((InhaltOptionRegister & 0x07) == 0x00)
                {
                    //WTD Rate = 1:2
                }
                else if ((InhaltOptionRegister & 0x07) == 0x01)
                {
                    //WTD Rate = 1:2
                }
                else if ((InhaltOptionRegister & 0x07) == 0x02)
                {
                    //WTD Rate = 1:4
                }
                else if ((InhaltOptionRegister & 0x07) == 0x03)
                {
                    //WTD Rate = 1:8
                }
                else if ((InhaltOptionRegister & 0x07) == 0x04)
                {
                    //WTD Rate = 1:16
                }
                else if ((InhaltOptionRegister & 0x07) == 0x05)
                {
                    //WTD Rate = 1:32
                }
                else if ((InhaltOptionRegister & 0x07) == 0x06)
                {
                    //WTD Rate = 1:64
                }
                else if ((InhaltOptionRegister & 0x07) == 0x07)
                {
                    //WTD Rate = 1:128
                }
                else
                {
                    MessageBox.Show("Something wrong with Watchdog");
                }
            }
            else if ((InhaltOptionRegister & 0x08) == 0x00) //Timer0: Prescaler is assigned to the Timer0 module
            {
                if ((InhaltOptionRegister & 0x07) == 0x00)
                {
                    //TMR0 Rate = 1:2
                    TimerValue = 2;
                    SetTimer0();
                }
                else if ((InhaltOptionRegister & 0x07) == 0x01)
                {
                    //TMR0 Rate = 1:4
                    TimerValue = 4;
                    SetTimer0();
                }
                else if ((InhaltOptionRegister & 0x07) == 0x02)
                {
                    //TMR0 Rate = 1:8
                    TimerValue = 8;
                    SetTimer0();
                }
                else if ((InhaltOptionRegister & 0x07) == 0x03)
                {
                    //TMR0 Rate = 1:16
                    TimerValue = 16;
                    SetTimer0();
                }
                else if ((InhaltOptionRegister & 0x07) == 0x04)
                {
                    //TMR0 Rate = 1:32
                    TimerValue = 32;
                }
                else if ((InhaltOptionRegister & 0x07) == 0x05)
                {
                    //TMR0 Rate = 1:64
                    TimerValue = 64;
                    SetTimer0();
                }
                else if ((InhaltOptionRegister & 0x07) == 0x06)
                {
                    //TMR0 Rate = 1:128
                    TimerValue = 128;
                    SetTimer0();
                }
                else if ((InhaltOptionRegister & 0x07) == 0x07)
                {
                    //TMR0 Rate = 1:256
                    TimerValue = 256;
                    SetTimer0();
                }
                else
                {
                    MessageBox.Show("Something wrong with Timer0");
                }
            }
            else
            {
                MessageBox.Show("Something wrong with PrescalerBit in Option Register");
            }
        }
Exemple #18
0
        public static void BTFSC(string commandAsString)
        {
            int    myLiteralAsNum = Convert.ToInt32(commandAsString, 16); // string zu int konvertieren
            string binary         = Convert.ToString(myLiteralAsNum, 2);  // int zu Binärstring konvertieren
            string fLiteralbinary = binary.Substring(6, 7);               //Argument, Adresse f auslesen
            string bLiteralbinary = binary.Substring(3, 3);               // Argument d auslesen ob 1 oder 0

            int  fAsInt           = Convert.ToInt32(fLiteralbinary, 2);   //Binäradresse wird als Int gespeichert
            byte fAsByteUnchecked = Convert.ToByte(fAsInt);

            byte fAsByte = CheckIndirectAddressing(fAsByteUnchecked); //Indirekte Adressierung wird überprüft

            byte fWert = Registerspeicher.getRegisterWert(fAsByte);

            int bAsInt = Convert.ToInt32(bLiteralbinary, 2); //B-binär wird als Int gespeichert

            if (bAsInt == 0)
            {
                if ((fWert & 0x01) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 1)
            {
                if ((fWert & 0x02) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 2)
            {
                if ((fWert & 0x04) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 3)
            {
                if ((fWert & 0x08) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 4)
            {
                if ((fWert & 0x10) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 5)
            {
                if ((fWert & 0x20) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 6)
            {
                if ((fWert & 0x40) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else if (bAsInt == 7)
            {
                if ((fWert & 0x80) == 0x00)
                {
                    MainWindow.CommandCounter++;
                    MainWindow.numberOfCycles = 2;
                }
            }
            else
            {
                MessageBox.Show("Problem BTFSC - b is not defined");
            }
        }
Exemple #19
0
 public static void LeseTrisBPortBInhalt()
 {
     inhaltPortB = Registerspeicher.getRegisterWert(Registerspeicher.PORTB); //Inhalt PortB wird vom Speicher geholt
     inhaltTrisB = Registerspeicher.getRegisterWert(0x86);                   //vom Speicher an Stelle 0x86 TRISB Register Wert wird geholt
 }
Exemple #20
0
        public static void CLRW(string commandAsString)
        {
            Registerspeicher.W = 0x00;          //Register w wird auf 0 gesetzt

            Registerspeicher.SetZeroFlag(0x00); //ZeroFlag wird auf 1 gesetzt
        }
Exemple #21
0
 public MainWindow()
 {
     InitializeComponent();
     LoadSpeicherGrid();
     Registerspeicher.initializeRegister();
 }