Example #1
0
        public override bool Verify(string[] lines, TheCpu cpu, out string error)
        {
            if (lines.Length > 0)
            {
                if (lines[0].ToUpper() != "CONSTANT")
                {
                    error = "Невалидна инструкция";
                    return(false);
                }
            }

            if (lines.Length > 1)
            {
                if (!lines[1].EndsWith(","))
                {
                    error = "Липсваща запетайка";
                    return(true);
                }
            }

            if (lines.Length == 3)
            {
                if (cpu.ValidLiteral(lines[2]))
                {
                    // CONSTANT literal, kk
                    var name = lines[1].Remove(lines[1].Length - 1).ToUpper();

                    if (cpu.Literals.ContainsKey(name))
                    {
                        cpu.Literals[name] = cpu.GetLiteral(lines[2]);
                    }
                    else
                    {
                        cpu.Literals.Add(name, cpu.GetLiteral(lines[2]));
                    }

                    error = null;
                    return(true);
                }
                else
                {
                    error = "Вторият аргумент на инструкцията трябва да е литерал";
                    return(true);
                }
            }

            error = "Невалидна инструкция";
            return(false);
        }
        public override bool Verify(string[] lines, TheCpu cpu, out string error)
        {
            if (lines.Length > 0)
            {
                if (lines[0].ToUpper() != commandString)
                {
                    error = "Невалидна инструкция";
                    return(false);
                }
            }

            if (lines.Length > 1)
            {
                if (!lines[1].EndsWith(","))
                {
                    error = "Липсваща запетайка";
                    return(true);
                }
                if (!cpu.ValidRegister(lines[1].Remove(lines[1].Length - 1)))
                {
                    error = "Първият аргумент на инструкцията трябва да е регистър";
                    return(true);
                }
            }

            if (lines.Length == 3)
            {
                if (cpu.ValidRegister(lines[2]))
                {
                    // CMD sX, sY
                    error = null;
                    return(true);
                }
                else if (cpu.ValidLiteral(lines[2]))
                {
                    // CMD sX, kk
                    error = null;
                    return(true);
                }
                else
                {
                    error = "Вторият аргумент на инструкцията трябва да е регистър или литерал";
                    return(true);
                }
            }

            error = "Невалидна инструкция";
            return(false);
        }
 public override void Execute(string[] lines, TheCpu cpu)
 {
     if (cpu.ValidRegister(lines[2]))
     {
         // CMD sX, sY
         this.ExecuteV1(lines[1].Remove(lines[1].Length - 1), lines[2], cpu);
     }
     else if (cpu.ValidLiteral(lines[2]))
     {
         // CMD sX, kk
         this.ExecuteV2(lines[1].Remove(lines[1].Length - 1), lines[2], cpu);
     }
     else
     {
         throw new ArgumentException("Невалидна инструкция.");
     }
 }
        public override void Execute(string[] lines, TheCpu cpu)
        {
            var parameter1 = lines[1].Remove(lines[1].Length - 1);
            var parameter2 = lines[2].Replace("(", "").Replace(")", "").Trim();

            if (cpu.ValidRegister(parameter2))
            {
                // CMD sX, sY
                this.ExecuteV1(parameter1, parameter2, cpu);
            }
            else if (cpu.ValidLiteral(lines[2]))
            {
                // CMD sX, kk
                this.ExecuteV2(parameter1, lines[2], cpu);
            }
            else
            {
                throw new ArgumentException("Невалидна инструкция.");
            }
        }