// Replace clear loop [-] with single instruction public List <InstructionBase> OptimizeClearLoop(List <InstructionBase> instructions) { List <InstructionBase> optimized = new List <InstructionBase>(); for (int i = 0; i < instructions.Count; i++) { InstructionBase instruction = instructions[i]; bool optimizationFound = false; if (instruction is OpenInstruction && i < instructions.Count - 2) { SubInstruction sub = instructions[i + 1] as SubInstruction; if (sub?.X == 1 && sub.Offset == 0 && instructions[i + 2] is CloseInstruction) { Debug.WriteLine("Clear loop found"); optimizationFound = true; optimized.Add(new ClearInstruction()); i += 2; } } if (!optimizationFound) { optimized.Add(instruction); } } return(optimized); }
public override int PrepareNextInstruction(InstructionBase instruction) { if (instruction is MergeSortInstruction) { MergeSortInstruction mergeSortInstruction = (MergeSortInstruction)instruction; } else if (instruction is MergeSortHolderInstruction) { } else { } // Display help on blackboard if (false) // help enabled { } else { //if (instruction.NextHolderID == Util.NO_INSTRUCTION) // skipping until next move // TODO: FIX Debug.Log("PrepareNextInstruction not implemented!"); return(1); } return(0); }
// --------------------------------------- Extra methods --------------------------------------- // Finds the number of instructions which the player has to do something to progress protected int FindNumberOfUserAction(Dictionary <int, InstructionBase> instructions) { Dictionary <string, List <string> > skipDict = GetTeachingAlgorithm().SkipDict; int count = 0; for (int x = 0; x < instructions.Count; x++) { InstructionBase inst = instructions[x]; if (inst is ListVisualInstruction) { continue; } if (skipDict.ContainsKey(Util.SKIP_NO_ELEMENT) && skipDict.ContainsKey(Util.SKIP_NO_DESTINATION)) { string instruction = instructions[x].Instruction; if (!skipDict[Util.SKIP_NO_ELEMENT].Contains(instruction) && !skipDict[Util.SKIP_NO_DESTINATION].Contains(instruction)) { count++; } } } return(count); }
public void CreatesMultipleBasicBlocksWhenBranchingInstructionsArePresent() { // Arrange. var instructions = new InstructionBase[] { new NormalInstruction(), new NormalInstruction(), new BranchingInstruction { BranchType = BranchType.Conditional }, new NormalInstruction() }; // Act. var controlFlowGraph = ControlFlowGraph.FromInstructions(instructions); // Assert. Assert.That(controlFlowGraph.BasicBlocks, Is.Not.Null); Assert.That(controlFlowGraph.BasicBlocks, Has.Count.EqualTo(2)); Assert.That(controlFlowGraph.BasicBlocks[0].Position, Is.EqualTo(0)); Assert.That(controlFlowGraph.BasicBlocks[0].Instructions, Has.Count.EqualTo(3)); Assert.That(controlFlowGraph.BasicBlocks[0].Successors, Has.Count.EqualTo(1)); Assert.That(controlFlowGraph.BasicBlocks[0].Successors[0], Is.EqualTo(controlFlowGraph.BasicBlocks[1])); Assert.That(controlFlowGraph.BasicBlocks[1].Position, Is.EqualTo(1)); Assert.That(controlFlowGraph.BasicBlocks[1].Instructions, Has.Count.EqualTo(1)); Assert.That(controlFlowGraph.BasicBlocks[1].Successors, Is.Empty); }
/// <summary> /// Obtiene el CSS de una línea /// </summary> private string GetCss(Program program, InstructionBase instruction, string tagParent) { string result = ""; // Obtiene el CSS de la instrucción if (instruction is InstructionLineCss) { result = GetLine(program, tagParent, instruction as InstructionLineCss) + Environment.NewLine; } else if (instruction is InstructionVariableIdentifier) { AddVariable(program, instruction as InstructionVariableIdentifier); } else if (instruction is InstructionIfDefined) { result += CallCheckDefined(instruction as InstructionIfDefined, tagParent); } else if (instruction is InstructionMedia) { result += GetMediaLine(program, tagParent, instruction as InstructionMedia) + Environment.NewLine; } else if (instruction is InstructionComment) { result += GetComment(instruction.Token.Value) + Environment.NewLine; } // Devuelve el resultado return(result); }
protected void InitNode(string algorithm) { SetNodeTextID(true); this.algorithm = algorithm; Dist = UtilGraph.INIT_NODE_DIST; Instruction = new InstructionBase(Util.INIT_INSTRUCTION, Util.NO_INSTRUCTION_NR); }
private static bool CheckParameterType(InstructionBase instruction, List <Value> parameters) { switch (instruction) { case LogicalBranch _: case LogicalDestination _: case LogicalEndOfFunction _: return(parameters.Count == 0); case LogicalDefineFunction logicalDefineFunction: return(CheckParameterType(logicalDefineFunction.InnerInstruction, logicalDefineFunction.Parameters.Append(Value.FromInteger(0)).ToList())); } if (_nonFixedInstructionsParameterPattern.TryGetValue(instruction.GetType(), out var pattern)) { var repeatingParametersCount = parameters.Count - (pattern.FirstTypes.Length + pattern.LastTypes.Length); if (repeatingParametersCount < 0) { return(false); } if (repeatingParametersCount % pattern.RepeatingTypes.Length != 0) { return(false); } for (var i = 0; i < repeatingParametersCount; ++i) { if (parameters[i + pattern.FirstTypes.Length].Type != pattern.RepeatingTypes[i % pattern.RepeatingTypes.Length]) { return(false); } } return(true); } if (_fixedInstructionsParameterTypes.TryGetValue(instruction.GetType(), out var parameterTypes)) { if (parameters.Count != parameterTypes.Length) { return(false); } for (var i = 0; i < parameters.Count; ++i) { if (parameters[i].Type != parameterTypes[i]) { return(false); } } return(true); } throw new NotImplementedException(); }
public override Dictionary <int, InstructionBase> UserTestInstructions(InstructionBase[] sortingElements) { Dictionary <int, InstructionBase> instructions = new Dictionary <int, InstructionBase>(); int instNr = 0, i = 0, j = 0; // Add first instruction instructions.Add(instNr, new InstructionBase(Util.FIRST_INSTRUCTION, instNr++)); int N = sortingElements.Length; // line 1 for (i = 0; i < N; i++) { instructions.Add(instNr, new InstructionLoop(UtilSort.UPDATE_LOOP_INST, instNr++, i, j, UtilSort.OUTER_LOOP)); for (j = 0; j < N - i - 1; j++) { // Update for loop instruction instructions.Add(instNr, new InstructionLoop(UtilSort.UPDATE_LOOP_INST, instNr++, i, j, UtilSort.INNER_LOOP)); // Choose sorting elements to compare BubbleSortInstruction comparison = MakeInstruction(sortingElements[j], sortingElements[j + 1], i, j, UtilSort.COMPARE_START_INST, instNr, true, false); // Add this instruction instructions.Add(instNr++, comparison); if (comparison.Value1 > comparison.Value2) { // Switch their positions instructions.Add(instNr, MakeInstruction(sortingElements[j], sortingElements[j + 1], i, j, UtilSort.SWITCH_INST, instNr++, true, false)); int holder1 = ((BubbleSortInstruction)sortingElements[j]).HolderID1; int holder2 = ((BubbleSortInstruction)sortingElements[j + 1]).HolderID1; InstructionBase temp = sortingElements[j]; sortingElements[j] = sortingElements[j + 1]; sortingElements[j + 1] = temp; // Update holderID ((BubbleSortInstruction)sortingElements[j]).HolderID1 = holder1; ((BubbleSortInstruction)sortingElements[j + 1]).HolderID1 = holder2; } // Add this instruction instructions.Add(instNr, MakeInstruction(sortingElements[j], sortingElements[j + 1], i, j, UtilSort.COMPARE_END_INST, instNr++, false, false)); } if (instructions[instructions.Count - 1] is BubbleSortInstruction) { ((BubbleSortInstruction)instructions[instructions.Count - 1]).IsSorted = true; } // Update end 2nd for-loop instruction instructions.Add(instNr, new InstructionLoop(UtilSort.UPDATE_LOOP_INST, instNr++, i, j, UtilSort.INNER_LOOP)); instructions.Add(instNr, new InstructionLoop(UtilSort.END_LOOP_INST, instNr++, i, j, UtilSort.INNER_LOOP)); } instructions.Add(instNr, new InstructionLoop(UtilSort.UPDATE_LOOP_INST, instNr++, i, j, UtilSort.OUTER_LOOP)); instructions.Add(instNr, new InstructionLoop(UtilSort.END_LOOP_INST, instNr++, i, j, UtilSort.OUTER_LOOP)); // Final instruction instructions.Add(instNr, new InstructionBase(Util.FINAL_INSTRUCTION, instNr++)); return(instructions); }
public List <InstructionBase> PobierzInstrukcjeMetody() { var metoda = PobierzOpisMetody(); //metoda var il = metoda.GetInstructions(); var instrukcje = il.Select(i => InstructionBase.UtworzInstrukcje(i)); return(instrukcje.ToList()); }
/// <summary> /// Obtiene una instrucción de error /// </summary> private InstructionBase GetInstructionError(Token token, string error) { InstructionBase instruction = new InstructionBase(token); // Indica que es un error instruction.Error = "Tipo de instrucción desconocida"; // Devuelve la instrucción return(instruction); }
private static void AssertBranchingInstruction( InstructionBase instruction, InstructionBase branchTarget, BranchType branchType) { Assert.That(instruction, Is.InstanceOf <BranchingInstruction>()); Assert.That(((BranchingInstruction)instruction).BranchTarget, Is.EqualTo(branchTarget)); Assert.That(((BranchingInstruction)instruction).BranchType, Is.EqualTo(branchType)); }
public void AddNonStandardInstruction(InstructionBase instruction) { if (_instructions.TryGetValue(instruction.OpCode, out var existingInstruction)) { throw new ArgumentException( $"Opcode {instruction.OpCode} was already in use by {existingInstruction.GetType().Name}", nameof(instruction)); } _instructions.Add(instruction.OpCode, instruction); }
// Help functions private BubbleSortInstruction MakeInstruction(InstructionBase inst1, InstructionBase inst2, int i, int j, string instruction, int instructionNr, bool isCompare, bool isSorted) { int seID1 = ((BubbleSortInstruction)inst1).SortingElementID1; int seID2 = ((BubbleSortInstruction)inst2).SortingElementID1; int hID1 = ((BubbleSortInstruction)inst1).HolderID1; int hID2 = ((BubbleSortInstruction)inst2).HolderID1; int value1 = ((BubbleSortInstruction)inst1).Value1; int value2 = ((BubbleSortInstruction)inst2).Value1; return(new BubbleSortInstruction(instruction, instructionNr, i, j, UtilSort.NO_VALUE, seID1, seID2, hID1, hID2, value1, value2, isCompare, isSorted)); }
private void Awake() { edges = new List <TutorialEdge>(); player = FindObjectOfType <Player>().GetComponentInChildren <Camera>().gameObject; tutorialTask = GetComponentInParent <TutorialGraphTask>(); animator = GetComponentInChildren <Animator>(); textNodeID = GetComponentInChildren <TextMeshPro>(); nodeID = textNodeID.text; Instruction = new InstructionBase(Util.INIT_INSTRUCTION, Util.NO_INSTRUCTION_NR); }
public InstructionFactory() { var instructions = new InstructionBase[] { new ClearMemoryInstruction(), new ConditionalSkipInstruction(), new JumpInstruction(), new SetMemoryInstruction(), }; _instructions = instructions.ToDictionary(i => i.Type); }
private void Step() { // Verify we're not at the end of the stream if (ExecutionState.PC >= Code.Length) { // If we reached the end, exit with the remainder of the gas and a success status. ExecutionState.Result = new EVMExecutionResult(this, null, true); return; } // Set our position back to the start of the instruction, grab our opcode and verify it. InstructionOpcode opcode = (InstructionOpcode)Code.Span[(int)ExecutionState.PC]; // Obtain our base cost for this opcode. If we fail to, the instruction isn't implemented yet. uint?instructionBaseGasCost = GasDefinitions.GetInstructionBaseGasCost(State.Configuration.Version, opcode); if (instructionBaseGasCost == null) { throw new EVMException($"Invalid opcode {opcode.ToString()} read when executing!"); } // If we just jumped, then this next opcode should be a JUMPDEST. if (ExecutionState.JumpedLastInstruction && opcode != InstructionOpcode.JUMPDEST) { throw new EVMException($"Invalid jump to offset {ExecutionState.PC} in code!"); } // Obtain our instruction implementation for this opcode var opcodeDescriptor = opcode.GetDescriptor(); InstructionBase instruction = opcodeDescriptor.GetInstructionImplementation(this); // Record our code coverage for this execution. CoverageMap?.RecordExecution(instruction.Offset, (ExecutionState.PC - instruction.Offset)); // Record our instruction execution tracing if (State.Configuration.DebugConfiguration.IsTracing) { State.Configuration.DebugConfiguration.ExecutionTrace?.RecordExecution(this, instruction, GasState.Gas, (BigInteger)instructionBaseGasCost); } // Deduct base gas cost GasState.Deduct((BigInteger)instructionBaseGasCost); // Debug: Print out instruction execution information. //if (opcode == InstructionOpcode.JUMPDEST) // Console.WriteLine($"\r\n---------------------------------------------------------------\r\n"); //Console.WriteLine($"0x{instruction.Offset.ToString("X4")}: {instruction}"); //Console.WriteLine($"Stack: {ExecutionState.Stack}"); // Execute the instruction instruction.Execute(); }
public void Execute() { //NS.Debug.VM = this; // do debugowania while (CallStack.IsEmpty() == false && Status != VirtualMachineState.Executed && AktualnaMetoda.CzyWykonywacInstrukcje) { var zmienneLokalne = AktualnaMetoda.LocalVariables; var argumenty = AktualnaMetoda.LocalArguments; var stos = CallStack; if (WirtualnaMaszyna.BreakpointIterationNumber == NumerIteracji) { Debugger.Break(); } //try { //if (NS.Debug.StopIterationNumber == NumerIteracji) //{ // System.Diagnostics.Debugger.Break(); //} aktualnaInstrukcja = PobierzAktualnaInstrukcje(); try { aktualnaInstrukcja.Wykonaj(); } catch (Exception ex) { throw new Exception($"Błąd w instrukcji {aktualnaInstrukcja} w metodzie {AktualnaMetoda}", ex); } NumerIteracji++; if (CallStack.IsEmpty()) { //kończymy wykonanie return; } continue; } //catch (Exception ex) //{ // CzyWykonywacInstrukcje = false; // //Status = VirtualMachineState.Exception; // //RzuconyWyjatekCalosc = ex.ToString(); // //RzuconyWyjatekWiadomosc = ex.Message; ; // //if (Debugger.IsAttached) // //{ // // Debugger.Break(); // //} // return; //} } }
public void CPU_NoInstructionsHaveCollidingOpCodes() { var seenInstructions = new InstructionBase[byte.MaxValue + 1]; foreach (var instruction in _cpu.InstructionSet.Where(i => i is not null)) { if (seenInstructions[instruction.OpCode] != null) { throw new Exception($"Opcode {instruction.OpCode} collides between {instruction.GetType().Name} and {seenInstructions[instruction.OpCode].GetType().Name}"); } seenInstructions[instruction.OpCode] = instruction; } }
/// <summary> /// Create a MIX instruction instance with the parameters contained in this object. /// </summary> /// <param name="instruction">MixInstruction to create an instance of. This method will throw an exception if this parameter is of a different instruction type.</param> /// <param name="status">AssemblingStatus object reflecting the current state of the assembly process</param> /// <returns></returns> public InstructionInstanceBase CreateInstance(InstructionBase instruction, AssemblingStatus status) { if (!(instruction is MixInstruction)) { throw new ArgumentException("instruction must be a MixInstruction", nameof(instruction)); } var mixInstruction = (MixInstruction)instruction; if (!AreValuesDefined(status)) { return(null); } var addressMagnitude = mAddress.GetMagnitude(status.LocationCounter); var word = new Word(MixInstruction.AddressByteCount); if (addressMagnitude > word.MaxMagnitude) { status.ReportError(LineSection.AddressField, 0, mIndexPartCharIndex, new MixAssembler.Finding.ParsingError("address value " + addressMagnitude + " invalid", (int)-word.MaxMagnitude, (int)word.MaxMagnitude)); return(null); } word.MagnitudeLongValue = addressMagnitude; var fieldSpecValue = GetFieldSpecValue(status, mixInstruction); if (fieldSpecValue == null) { return(null); } var instructionWord = new FullWord { Sign = mAddress.GetSign(status.LocationCounter) }; for (int i = 0; i < word.ByteCount; i++) { instructionWord[i] = word[i]; } instructionWord[MixInstruction.IndexByte] = (int)mIndex.GetValue(status.LocationCounter); instructionWord[MixInstruction.FieldSpecByte] = fieldSpecValue; instructionWord[MixInstruction.OpcodeByte] = mixInstruction.Opcode; var instance = mixInstruction.CreateInstance(instructionWord); ReportInstanceErrors(status, instance); return(instance); }
// Fetch instruction protected virtual void DemoUpdate() { if (newDemoImplemented) { InstructionBase instruction = null; // Step by step activated by pausing, and step requested if (userPausedTask && demoManager.PlayerMove) { demoManager.PlayerMove = false; instruction = demoManager.GetStep(); bool increment = demoManager.PlayerIncremented; PerformInstruction(instruction, increment); } else if (!userPausedTask && demoManager.HasInstructions()) // Demo mode { // First check if user test setup is complete if (!WaitingForSupportToFinish())//waitForSupportToComplete == 0) { instruction = demoManager.GetInstruction(); //Debug.Log("Current: " + demoManager.CurrentInstructionNr + ", Actual: " + instruction.InstructionNr); PerformInstruction(instruction, true); demoManager.IncrementToNextInstruction(); } } // Debugging if (instruction != null && prevInstruction != instruction.Instruction) { prevInstruction = instruction.DebugInfo(); Debug.Log(instruction.DebugInfo()); if (useDebugText && debugText != null) { if (deleteWhenReached <= 0) { debugText.text = instruction.DebugInfo(); deleteWhenReached = debugLineNumbers; } else { debugText.text += "\n" + instruction.DebugInfo(); } deleteWhenReached--; } } } }
private InstructionModel CreateInstruction() { //Get an instruction type InstructionType instructionType = (InstructionType)_random.Next(0, (int)InstructionType.ConditionalSkip + 1); //Get the instruction implementation InstructionBase instruction = _instructionFactory[instructionType]; //Create the context var context = new InstructionCreationContext(_random, _memorySize, _numberOfInstructions); //finally, create the damn instruction return(instruction.Create(context)); }
public static string InstructionName(this InstructionBase instruction) { switch (instruction) { case LogicalDestination destination: return("BranchDestination"); case LogicalEndOfFunction endOfFunction: return("EndOfFunction"); default: return(instruction.Type.ToString()); } }
public void ResetNode() { ChangeAppearance(Util.STANDARD_COLOR); Instruction = new InstructionBase(Util.INIT_INSTRUCTION, Util.NO_INSTRUCTION_NR); visited = false; traversed = false; visitNextMove = false; traverseNextMove = false; animator.SetBool(UtilGraph.NODE_VISIT_ANIMATION, false); animator.SetBool(UtilGraph.NODE_TRAVERSE_ANIMATION, false); prevEdge = null; }
/// <summary> /// Create a loader instruction instance with the parameters contained in this object. /// </summary> /// <param name="instruction">LoaderInstruction to create an instance of. This method will throw an exception if this parameter is of a different instruction type.</param> /// <param name="status">AssemblingStatus object reflecting the current state of the assembly process</param> /// <returns></returns> public InstructionInstanceBase CreateInstance(InstructionBase instruction, AssemblingStatus status) { if (!(instruction is LoaderInstruction)) { throw new ArgumentException("instruction must be a LoaderInstruction", nameof(instruction)); } var loaderInstruction = (LoaderInstruction)instruction; if (!mValue.IsValueDefined(status.LocationCounter)) { status.ReportParsingError(LineSection.AddressField, 0, mTextLength, "value is not defined"); return(null); } return(new LoaderInstruction.Instance(loaderInstruction, mValue.GetSign(status.LocationCounter), mValue.GetMagnitude(status.LocationCounter))); }
public void Execute(List <InstructionBase> instructions) { // Set open/close instruction ptr Stack <int> loopStack = new Stack <int>(); for (int instructionPtr = 0; instructionPtr < instructions.Count; instructionPtr++) { InstructionBase instruction = instructions[instructionPtr]; switch (instruction) { case OpenInstruction _: loopStack.Push(instructionPtr); // save OpenInstructionPtr, will be set later break; case CloseInstruction _ when loopStack.Count == 0: throw new InvalidOperationException($"Unmatched CloseInstruction at position {instructionPtr}."); case CloseInstruction closeInstruction: { int loopStartPtr = loopStack.Pop(); closeInstruction.OpenInstructionPtr = loopStartPtr; // set OpenInstructionPtr to previously saved ptr ((OpenInstruction)instructions[loopStartPtr]).CloseInstructionPtr = instructionPtr; // set CloseInstructionPtr to current ptr break; } } } if (loopStack.Count > 0) { throw new InvalidOperationException($"Unmatched OpenInstruction at position { loopStack.Peek()}."); } // int[] memory = new int[65536]; int memoryPtr = 32765; // starts in the middle int ip = 0; while (true) { if (ip >= instructions.Count) { break; // stop program } InstructionBase instruction = instructions[ip]; instruction.Execute(memory, ref memoryPtr, ref ip); ip++; } }
/// <summary> /// Creates an instance of this class by parsing the address field of a loader instruction. /// </summary> /// <param name="instruction">LoaderInstruction to parse the address field for. This method will throw an exception if this parameter is of a different instruction type.</param> /// <param name="addressField">The address field to parse.</param> /// <param name="status">ParsingStatus object reflecting the current state of the parse process</param> /// <returns></returns> public static IInstructionParameters ParseAddressField(InstructionBase instruction, string addressField, ParsingStatus status) { if (!(instruction is LoaderInstruction)) { throw new ArgumentException("instruction must be a LoaderInstruction", nameof(instruction)); } var loaderInstruction = (LoaderInstruction)instruction; IValue address = loaderInstruction.Alphanumeric ? CharacterConstantValue.ParseValue(addressField, 0, status) : WValue.ParseValue(addressField, 0, status); if (address == null) { status.ReportParsingError(0, addressField.Length, "unable to parse value"); return(null); } return(new LoaderInstructionParameters(address, addressField.Length)); }
/// <summary> /// Lee una instrucción de código /// </summary> private InstructionBase ReadCommand(Token token) { InstructionBase instruction = null; // Lee el siguiente token token = GetToken(); // Interpreta la sentencia if (token.Type != Token.TokenType.Sentence) { instruction = GetInstructionError(token, "Sentencia desconocida"); } else { instruction = ReadSentence(token); } // Devuelve la instrucción return(instruction); }
public override int PrepareNextInstruction(InstructionBase instruction) { Debug.Log(instruction.DebugInfo()); bool gotSortingElement = !insertionSort.SkipDict[UtilSort.SKIP_NO_ELEMENT].Contains(instruction.Instruction); bool noDestination = insertionSort.SkipDict[UtilSort.SKIP_NO_DESTINATION].Contains(instruction.Instruction); if (gotSortingElement) { InsertionSortInstruction insertionSortInstruction = (InsertionSortInstruction)instruction; // Get the Sorting element InsertionSortElement sortingElement = sortMain.ElementManager.GetSortingElement(insertionSortInstruction.SortingElementID).GetComponent <InsertionSortElement>(); // Hands out the next instruction sortingElement.Instruction = insertionSortInstruction; // Give this sorting element permission to give feedback to progress to next intstruction switch (instruction.Instruction) { case UtilSort.PIVOT_START_INST: case UtilSort.COMPARE_START_INST: case UtilSort.PIVOT_END_INST: case UtilSort.SWITCH_INST: sortingElement.NextMove = true; break; } //if (instruction.Instruction == UtilSort.PIVOT_START_INST || instruction.Instruction == UtilSort.PIVOT_END_INST || instruction.Instruction == UtilSort.SWITCH_INST) // sortingElement.NextMove = true; } // Display help on blackboard if (sortMain.SortSettings.Difficulty <= UtilSort.BEGINNER) { sortMain.WaitForSupportToComplete++; StartCoroutine(sortMain.GetTeachingAlgorithm().UserTestHighlightPseudoCode(instruction, gotSortingElement)); } if (gotSortingElement && !noDestination) { return(0); } return(1); }
// Decode and execute instruction protected void PerformInstruction(InstructionBase instruction, bool increment) { if (instruction.Status == Util.EXECUTED_INST && increment) { return; } waitForSupportToComplete++; StartCoroutine(GetTeachingAlgorithm().ExecuteDemoInstruction(instruction, increment)); if (increment) { instruction.Status = Util.EXECUTED_INST; } else { instruction.Status = Util.NOT_EXECUTED; } }
/// <summary> /// Creates an instance of this class by parsing the address field of a MIX instruction. /// </summary> /// <param name="instruction">MixInstruction to parse the address field for. This method will throw an exception if this parameter is of a different instruction type.</param> /// <param name="addressField">The address field to parse.</param> /// <param name="status">ParsingStatus object reflecting the current state of the parse process</param> /// <returns></returns> public static IInstructionParameters ParseAddressField(InstructionBase instruction, string addressField, ParsingStatus status) { var indexCharIndex = addressField.IndexOf(','); var sectionCharIndex = addressField.IndexOf('(', Math.Max(indexCharIndex, 0)); if (sectionCharIndex == -1) { sectionCharIndex = addressField.Length; } if (indexCharIndex == -1) { indexCharIndex = sectionCharIndex; } var address = APartValue.ParseValue(addressField.Substring(0, indexCharIndex), 0, status); if (address == null) { status.ReportParsingError(0, indexCharIndex, "unable to parse address"); return(null); } var index = IPartValue.ParseValue(addressField.Substring(indexCharIndex, sectionCharIndex - indexCharIndex), indexCharIndex, status); if (index == null) { status.ReportParsingError(indexCharIndex, sectionCharIndex - indexCharIndex, "unable to parse index"); return(null); } var field = FPartValue.ParseValue(addressField.Substring(sectionCharIndex), sectionCharIndex, status); if (field == null) { status.ReportParsingError(sectionCharIndex, addressField.Length - sectionCharIndex, "unable to parse field"); return(null); } return(new MixInstructionParameters(address, indexCharIndex, index, sectionCharIndex, field, addressField.Length)); }
public override bool BranchesTo(InstructionBase otherInstruction) { return BranchTarget == otherInstruction; }