Пример #1
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;
            }
        }
Пример #2
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;
            }
        }
Пример #3
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;
            }
        }