/*Операция*/ public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { string source = parametrs.Trim(); int value = 0; /*Проверка: если операнд -- число, то получаем значение, если операнд -- регистр, то получаем значение из регистра.*/ int ifSourceHasCount = source.IndexOfAny(new char[] { '1','2','3','4','5', '6','7','8','9','0'}); if (ifSourceHasCount == -1) { if (source.Length == 3 && source[0] == 'e' && source[2] == 'x') { for (char c = 'a'; c < 'i'; c++) { if (source[1] == c) { value = CurrentStatement.GetRegister(source); c = 'i'; } else if (c == 'h') { throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); } } } } else { value = int.Parse(source); } /*Помещаем значение в стек*/ CurrentStatement.Push(new HomeworkWPF.StackItem { Data = value, Address = false }); } throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }
/*Операция*/ public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { string destination = parametrs.Trim(); int address = 0; int count = 0; /*Проверка: если операнд -- адрес, то получаем значение, если операнд -- метка, то получаем адрес метки.*/ if (destination[destination.Count() - 1] == 'h') { address = Int32.Parse(destination, System.Globalization.NumberStyles.HexNumber); } else { foreach (HomeworkWPF.CommandItem i in CurrentStatement.Commands) { if (i.Command.Contains(parametrs + ":") == true) { address = i.Address; } } } /*Помещаем в стек адрес возврата*/ foreach (HomeworkWPF.CommandItem i in CurrentStatement.Commands) { if (i.Address == address) { CurrentStatement.Push(new HomeworkWPF.StackItem { Data = CurrentStatement.Commands[CurrentStatement.CurrentCommand].Address, Address = true }); CurrentStatement.CurrentCommand = count - 1; return; } count++; } } throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }