private static void ProcessValue(CpuToken token, Cpu cpu, InstructionField requirement) { if (requirement == null) { return; } switch (requirement.Type) { case CpuFieldType.Ignore: throw new UnexpectedInstructionException(); case CpuFieldType.Value: cpu.Memory.SetValue(token.Value.ToCpuValueFromInt(requirement.Size), counter); counter += requirement.Size; ProcessIgnoredFields(); break; case CpuFieldType.Address: ProcessAddress(cpu, token, requirement); break; default: throw new ArgumentOutOfRangeException(); } }
private static void ProcessAddress(Cpu cpu, CpuToken token, InstructionField requirement) { cpu.Memory.SetValue( int.TryParse(token.Value, out var number) ? number.ToCpuValue(requirement.Size) : labels[token.Value].ToCpuValue(requirement.Size), counter); counter += requirement.Size; ProcessIgnoredFields(); }
private static void ProcessInstruction(CpuToken token, Cpu cpu, InstructionField requirement) { if (IsInvalidInstruction(requirement)) { throw new UnexpectedInstructionException(); } var op = cpu.Instructions.NameToOpcode(token.Value); cpu.Memory.SetValue(op, counter); stack.PushRange(cpu.Instructions.GetInstruction(token.Value).Fields); ProcessIgnoredFields(); counter += cpu.Configuration.OpCodeSize; }