Esempio n. 1
0
        private static void MyCommand(string command)
        {
            string[] words = Checker.FormattingMyCommand(command);
            switch (words[0])
            {
            case "mov":

                if (!Checker.CheckCommandMOVandADD(words))
                {
                    Console.WriteLine("Error entering command MOV");
                }
                else
                {
                    ALU.MOV(words[1], words[2]);
                }
                break;

            case "add":
                CPU.ClearFlags();
                if (!Checker.CheckCommandMOVandADD(words))
                {
                    Console.WriteLine("Error entering command ADD");
                }
                else
                {
                    ALU.ADD(words[1], words[2]);
                }
                break;

            case "sub":
                CPU.ClearFlags();
                if (!Checker.CheckCommandMOVandADD(words))
                {
                    Console.WriteLine("Error entering command SUB");
                }
                else
                {
                    ALU.SUB(words[1], words[2]);
                }
                break;

            case "mul":
                CPU.ClearFlags();
                if (!Checker.CheckCommandMULandDIV(words))
                {
                    Console.WriteLine("Error entering command MUL");
                }
                else
                {
                    ALU.MUL(words[1]);
                }
                break;

            case "div":
                CPU.ClearFlags();
                if (!Checker.CheckCommandMULandDIV(words))
                {
                    Console.WriteLine("Error entering command DIV");
                }
                else
                {
                    ALU.DIV(words[1]);
                }
                break;

            case "fmov":
                if (!Checker.CheckCommandFMOV(words))
                {
                    Console.WriteLine("Error entering command FMOV");
                }
                else
                {
                    SCPU.FMOV(words[1], words[2]);
                }
                break;

            case "fadd":
                if (!Checker.CheckCommandFloat(words))
                {
                    Console.WriteLine("Error entering command FADD");
                }
                else
                {
                    SCPU.FADD(words[1], words[2]);
                }
                break;

            case "fsub":
                if (!Checker.CheckCommandFloat(words))
                {
                    Console.WriteLine("Error entering command FSUB");
                }
                else
                {
                    SCPU.FSUB(words[1], words[2]);
                }
                break;

            case "fmul":
                if (!Checker.CheckCommandFloat(words))
                {
                    Console.WriteLine("Error entering command FMUL");
                }
                else
                {
                    SCPU.FMUL(words[1], words[2]);
                }
                break;

            case "fdiv":
                if (!Checker.CheckCommandFloat(words))
                {
                    Console.WriteLine("Error entering command FDIV");
                }
                else
                {
                    SCPU.FDIV(words[1], words[2]);
                }
                break;

            case "tasks":
                if (words.Length == 1)
                {
                    MyTasks();
                }
                else
                {
                    Console.WriteLine("Error entering command TASKS");
                }
                break;

            default:
                Console.WriteLine("Error command!");
                break;
            }
        }
Esempio n. 2
0
        public static void VisualCommandDIV(long val1, long val2, string reg)
        {
            string first = "", second = "";
            bool   isNeg = Checker.IsNegativeResultForMUL(val1, val2);

            Checker.ConvertBinaryValueForDIV(val1, val2, ref first, ref second);
            if (Math.Abs(val1) < Math.Abs(val2))
            {
                VisualIfNothingNot(val1, val2, first, second, reg);
                return;
            }
            string ans = "";

            string help = "";
            int    step = 0, len = Math.Max(first.Length, second.Length), padleft = 0;

            Console.WriteLine("{0, -7}| {1}| {2}{4}{3}", "Step:", first, second, "|Answer:", new string(' ', first.Length * 2 + 2 - second.Length));

            bool exit = false;
            int  i    = 0;

            while (true)
            {
                if (!exit)
                {
                    if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                    {
                        exit = true;
                    }
                }

                help += first[i];
                int l = help.Length;
                help     = help.TrimStart('0');
                padleft += (l - help.Length);

                Console.Write("Step{0} | {1}", (++step).ToString("D2"), (help == "" ? "0" : help).PadLeft(padleft + help.Length));
                if (!Checker.Equals(help, second))
                {
                    ans += "0";
                    ans  = ans.TrimStart('0');
                }
                else
                {
                    ans     += "1";
                    l        = help.Length;
                    help     = ALU.SUBforDiv(help, second);
                    padleft += (l - help.Length);
                }
                Console.WriteLine("{1}|{0}", ans, new string(' ', first.Length * 3 - help.Length - padleft + 4));
                if (++i == first.Length)
                {
                    break;
                }
            }

            if (ans == "")
            {
                ans = "0";
            }
            if (help == "")
            {
                help = "0";
            }

            long div = Convert.ToInt64(ans, 2);
            long mod = Convert.ToInt64(help, 2);

            if (isNeg)
            {
                div = -div;
                mod = -mod;
            }

            Console.WriteLine("\nAnswer = {0} = {1}({2})", ans, div, div.ToString("X4").Substring(div.ToString("X4").Length - 4));
            Console.WriteLine("Modulo = {0} = {1}({2})", help, mod, mod.ToString("X4").Substring(mod.ToString("X4").Length - 4));
            if (reg[1] == 'l' || reg[1] == 'h')
            {
                Console.WriteLine("AH = {1}, AL = {0}", div.ToString("X2").Substring(div.ToString("X").Length - 4), mod.ToString("X2").Substring(mod.ToString("X2").Length - 4));
            }
            else
            {
                Console.WriteLine("AX = {0}, DX = {1}", div.ToString("X4").Substring(div.ToString("X4").Length - 4), mod.ToString("X4").Substring(mod.ToString("X4").Length - 4));
            }
        }