示例#1
0
        public static void CMP(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;

            var match = Regex.Match(line, @"CMP\s+([\w])");

            if (match.Success)
            {
                Register from = AssemblyUtility.IsRegister(match.Groups[1].Value);
                if (from != null)
                {
                    byte value1;
                    if (match.Groups[1].Value == "M")
                    {
                        if (I8085.M < I8085.MemorySize && I8085.M >= 0)
                        {
                            value1 = I8085.Memory[I8085.M].Data;
                        }
                        else
                        {
                            result.SetError("CMP instruction value out of bound:" + I8085.M);
                            return;
                        }
                    }
                    else
                    {
                        value1 = from.Value;
                    }

                    if (I8085.A.Value < value1)
                    {
                        I8085.Flag_C.Value = true;
                        I8085.Flag_Z.Value = false;
                    }
                    else if (I8085.A.Value == value1)
                    {
                        I8085.Flag_C.Value = false;
                        I8085.Flag_Z.Value = true;
                    }
                    else
                    {
                        I8085.Flag_C.Value = false;
                        I8085.Flag_Z.Value = false;
                    }
                }
                else
                {
                    result.SetError("CMP instruction work with  Register Only.");
                    return;
                }
                line = line.Replace(match.Groups[0].Value, string.Empty);
            }
            else
            {
                result.SetError("CMP instruction is incorrectly formatted");
                return;
            }
        }
示例#2
0
        public static void MVI(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;

            var match = Regex.Match(line, @"MVI\s+([a-zA-Z])\s*\,\s*(\d{1,}H?)");

            if (match.Success)
            {
                Register to = AssemblyUtility.IsRegister(match.Groups[1].Value);
                if (to != null)
                {
                    bool valueHexType = match.Groups[2].Value.ToLower().IndexOf("h") > 0;
                    byte value;
                    if (valueHexType)
                    {
                        string val = match.Groups[2].Value.ToLower().Replace("h", string.Empty);
                        value = Convert.ToByte(val, 16);
                    }
                    else
                    {
                        value = Convert.ToByte(match.Groups[2].Value, 10);
                    }

                    if (value >= 0 && value <= 255)
                    {
                        if (match.Groups[1].Value == "M")
                        {
                            I8085.Memory[I8085.M].Data = value;
                            result.RegistersChanged.Add(new Register(I8085.M.ToString().PadLeft(4, '0'),
                                                                     null, I8085.Memory[I8085.M].Data));
                        }
                        else
                        {
                            to.Value = value;
                            result.RegistersChanged.Add(to);
                        }
                    }
                    else
                    {
                        result.SetError("MVI should utilized 8 bit data only ie from 00-FF or 0-255");
                        return;
                    }
                    line = line.Replace(match.Groups[0].Value, string.Empty);
                }
                else
                {
                    result.SetError("MVI instruction work with Register to Register Only.");
                    return;
                }
            }
            else
            {
                result.SetError("MVI instruction is incorrectly formatted" + line);
                return;
            }
        }
示例#3
0
        public static void MOV(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;

            var match = Regex.Match(line, @"MOV\s+(\w)\s*\,\s*(\w)");

            if (match.Success)
            {
                Register to   = AssemblyUtility.IsRegister(match.Groups[1].Value);
                Register from = AssemblyUtility.IsRegister(match.Groups[2].Value);

                if (to != null && from != null)
                {
                    if (match.Groups[1].Value == "M" && match.Groups[2].Value == "M")
                    {
                        I8085.M = I8085.M;
                    }
                    else if (match.Groups[1].Value == "M")
                    {
                        I8085.Memory[I8085.M].Data = from.Value;
                        result.RegistersChanged.Add(new Register(I8085.M.ToString().PadLeft(4, '0'),
                                                                 null, I8085.Memory[I8085.M].Data));
                    }
                    else if (match.Groups[2].Value == "M")
                    {
                        to.Value = I8085.Memory[I8085.M].Data;
                        result.RegistersChanged.Add(to);
                    }
                    else
                    {
                        to.Value = from.Value;
                        result.RegistersChanged.Add(to);
                    }
                }
                else
                {
                    result.SetError("MOV instruction work with Register to Register Only.");
                    return;
                }

                line = line.Replace(match.Groups[0].Value, string.Empty);
            }
            else
            {
                result.SetError("MOV instruction is incorrectly formatted");
                return;
            }
        }
示例#4
0
        public static void DCR(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;

            var match = Regex.Match(line, @"DCR\s+([\w])");

            if (match.Success)
            {
                Register from = AssemblyUtility.IsRegister(match.Groups[1].Value);
                if (from != null)
                {
                    if (match.Groups[1].Value == "M")
                    {
                        AssemblyUtility.AddAdjustFlags(I8085.M, 1, false);
                        I8085.M -= 1;
                        if (I8085.M < I8085.MemorySize && I8085.M >= 0)
                        {
                            result.RegistersChanged.Add(new Register(I8085.M.ToString().PadLeft(4, '0'),
                                                                     null, I8085.Memory[I8085.M].Data));
                        }
                        else
                        {
                            result.SetError("INR instruction value out of bound:" + I8085.M);
                            return;
                        }
                    }
                    else
                    {
                        AssemblyUtility.SubAdjustFlags(from.Value, 1, false);
                        from.Value -= 1;
                        result.RegistersChanged.Add(I8085.A);
                    }
                }
                else
                {
                    result.SetError("DCR instruction work with  Register Only.");
                    return;
                }
                line = line.Replace(match.Groups[0].Value, string.Empty);
            }
            else
            {
                result.SetError("DCR instruction is incorrectly formatted");
                return;
            }
        }
示例#5
0
        public static void CMA(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;

            var match = Regex.Match(line, @"CMA");

            if (match.Success)
            {
                I8085.A.Value = AssemblyUtility.Compliment(I8085.A.Value);
                line          = line.Replace(match.Groups[0].Value, string.Empty);
            }
            else
            {
                result.SetError("CMA instruction is incorrectly formatted");
                return;
            }
        }
示例#6
0
        public static void SBB(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;

            var match = Regex.Match(line, @"SBB\s+([\w])");

            if (match.Success)
            {
                Register from = AssemblyUtility.IsRegister(match.Groups[1].Value);
                if (from != null)
                {
                    if (match.Groups[1].Value == "M")
                    {
                        AssemblyUtility.SubAdjustFlags(I8085.A.Value, I8085.Memory[I8085.M].Data,
                                                       Convert.ToByte(I8085.Flag_C.Value));

                        I8085.A.Value -= I8085.Memory[I8085.M].Data;
                        I8085.A.Value -= Convert.ToByte(I8085.Flag_C.Value);

                        result.RegistersChanged.Add(I8085.A);
                    }
                    else
                    {
                        AssemblyUtility.SubAdjustFlags(I8085.A.Value, from.Value, Convert.ToByte(I8085.Flag_C.Value));
                        I8085.A.Value -= from.Value;
                        I8085.A.Value -= (byte)(I8085.Flag_C.Value ? 1 : 0);
                        result.RegistersChanged.Add(I8085.A);
                    }
                }
                else
                {
                    result.SetError("SBB instruction work with  Register Only.");
                    return;
                }
                line = line.Replace(match.Groups[0].Value, string.Empty);
            }
            else
            {
                result.SetError("SBB instruction is incorrectly formatted");
                return;
            }
        }
示例#7
0
        public static void SBI(ref string line, LineAssembleResult result)
        {
            result.FutureLineNumber = result.LineNumber + 1;


            var match = Regex.Match(line, @"SBI\s+(\d{1,}H?)");

            if (match.Success)
            {
                bool valueHexType = match.Groups[1].Value.ToLower().IndexOf("h") > 0;
                byte value;
                if (valueHexType)
                {
                    string val = match.Groups[1].Value.ToLower().Replace("h", string.Empty);
                    value = Convert.ToByte(val, 16);
                }
                else
                {
                    value = Convert.ToByte(match.Groups[1].Value, 10);
                }
                if (value >= 0 && value <= 255)
                {
                    AssemblyUtility.SubAdjustFlags(I8085.A.Value, value, Convert.ToByte(I8085.Flag_C.Value));
                    I8085.A.Value -= value;
                    I8085.A.Value -= (byte)(I8085.Flag_C.Value ? 1 : 0);
                    result.RegistersChanged.Add(I8085.A);
                }
                else
                {
                    result.SetError("SBI should utilized 8 bit data only ie from 00-FF or 0-255");
                    return;
                }
                line = line.Replace(match.Groups[0].Value, string.Empty);
            }
            else
            {
                result.SetError("SBI instruction is incorrectly formatted");
                return;
            }
        }