public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { string source = parametrs.Trim(); HomeworkWPF.StackItem item = CurrentStatement.Pop(); int value = item.Data; /*Проверка: операнд -- регистр, то помещаем значение в регистр, иначе ошибка.*/ 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) { /*Помещаем значение в регистр*/ CurrentStatement.SetRegister(source, value); return; } } } } } else { throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); } }
/*Операция*/ public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { int comma = parametrs.IndexOf(','); string left = parametrs.Substring(0, comma); string right = parametrs.Substring(comma + 1); right = right.Trim(); int rightValue = 0; int result = 0; /*Проверка: если правый операнд -- число, то получаем значение, если правый операнд -- регистр, то получаем значение из регистра.*/ int ifRightHasCount = right.IndexOfAny(new char[] { '1','2','3','4','5', '6','7','8','9','0'}); if (ifRightHasCount == -1) { if (right.Length == 3 && right[0] == 'e' && right[2] == 'x') { for (char c = 'a'; c < 'i'; c++) { if (right[1] == c) { rightValue = CurrentStatement.GetRegister(right); c = 'i'; } } } } else { rightValue = int.Parse(right); } if (left.Length == 3 && left[0] == 'e' && left[2] == 'x') { for (char c = 'a'; c < 'i'; c++) { if (left[1] == c) { /*Находим значение левого операнда (регистра).*/ result = CurrentStatement.GetRegister(left) + rightValue; /*Помещаем результат выполнения операции в регистор.*/ CurrentStatement.SetRegister(left, result); return; } } } } throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }
/*Операция*/ 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 == "") { int address = 0; HomeworkWPF.StackItem item = null; int count = 0; /*Ищем в стеке адрес возврата.*/ while (address == 0 && CurrentStatement.MicroStack.Count > 0) { item = CurrentStatement.Pop(); if (item.Address == true) { address = item.Data; } } /*Переходим по адресу. Меняем индекс обрабатываемой команды.*/ foreach (HomeworkWPF.CommandItem i in CurrentStatement.Commands) { if (i.Address == address) { CurrentStatement.CurrentCommand = count; return; } count++; } } throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }
/*Операция*/ public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { int comma = parametrs.IndexOf(','); string left = parametrs.Substring(0, comma); string right = parametrs.Substring(comma + 1); right = right.Trim(); int rightValue = 0; int result = 0; /*Проверка: если правый операнд -- порт, то получаем его значение, иначе исключение.*/ int ifRightHasCount = right.IndexOfAny(new char[] { '1','2','3','4','5', '6','7','8','9','0'}); if (ifRightHasCount == -1) { if (right.Length == 5 && right.Contains("port")) { for (char c = 'A'; c < 'E'; c++) { if (right[4] == c) { /*Считываем значение из порта (правый операнд).*/ rightValue = CurrentStatement.GetPort(right); c = 'E'; } } } } else { throw new HomeworkWPF.ParseCommandException( CurrentStatement.Commands[CurrentStatement.CurrentCommand]); } if (left.Length == 3 && left[0] == 'e' && left[2] == 'x') { for (char c = 'a'; c < 'i'; c++) { if (left[1] == c) { /*Записываем значение в регистр (левый операнд).*/ result = rightValue; CurrentStatement.SetRegister(left, result); return; } } } } throw new HomeworkWPF.ParseCommandException( CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }
/*Операция*/ public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { CurrentStatement.Ecx = CurrentStatement.Ecx - 1; /*Проверка: если ecx > 0, то переходим по метке, иначе переходим на следующуюю команду.*/ if (CurrentStatement.Ecx > 0) { 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(destination + ":") == true) { address = i.Address; } } } /*Переходим по адресу. Меняем индекс текущей команды.*/ foreach (HomeworkWPF.CommandItem i in CurrentStatement.Commands) { if (i.Address == address) { CurrentStatement.CurrentCommand = count - 1; return; } count++; } } else { return; } } 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.CurrentCommand = count - 1; return; } count++; } } throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }
/*Операция*/ public void Operate(ref HomeworkWPF.Core CurrentStatement, string parametrs) { if (parametrs != "") { int comma = parametrs.IndexOf(','); string left = parametrs.Substring(0, comma); string right = parametrs.Substring(comma + 1); right = right.Trim(); int leftValue = 0; int rightValue = 0; /*Проверка: если правый операнд -- число, то получаем значение, если правый операнд -- регистр, то получаем значение из регистра.*/ int ifRightHasCount = right.IndexOfAny(new char[] { '1','2','3','4','5', '6','7','8','9','0'}); if (ifRightHasCount == -1) { if (right.Length == 3 && right[0] == 'e' && right[2] == 'x') { for (char c = 'a'; c < 'i'; c++) { if (right[1] == c) { rightValue = CurrentStatement.GetRegister(right); c = 'i'; } } } } else { rightValue = int.Parse(right); } /*Проверка: если левый операнд -- число, то получаем значение, если левый операнд -- регистр, то получаем значение из регистра.*/ int ifLeftHasCount = left.IndexOfAny(new char[] { '1','2','3','4','5', '6','7','8','9','0'}); if (ifLeftHasCount == -1) { if (left.Length == 3 && left[0] == 'e' && left[2] == 'x') { for (char c = 'a'; c < 'i'; c++) { if (left[1] == c) { leftValue = CurrentStatement.GetRegister(left); c = 'i'; } } } } else { leftValue = int.Parse(left); } /*Сравнение: если a >= b, то ZF=1, иначе ZF=0.*/ if (leftValue >= rightValue) { CurrentStatement.ZF = 1; } else { CurrentStatement.ZF = 0; } return; } throw new HomeworkWPF.ParseCommandException(CurrentStatement.Commands[CurrentStatement.CurrentCommand]); }