public override bool Verify(string[] lines, TheCpu cpu, out string error) { if (lines.Length > 0) { if (lines[0].ToUpper() != commandString) { error = "Невалидна инструкция"; return(false); } } if (lines.Length > 1) { if (!lines[1].EndsWith(",")) { error = "Липсваща запетайка"; return(true); } if (!cpu.ValidRegister(lines[1].Remove(lines[1].Length - 1))) { error = "Първият аргумент на инструкцията трябва да е регистър"; return(true); } } if (lines.Length == 3) { if (cpu.ValidRegister(lines[2])) { // CMD sX, sY error = null; return(true); } else if (cpu.ValidLiteral(lines[2])) { // CMD sX, kk error = null; return(true); } else { error = "Вторият аргумент на инструкцията трябва да е регистър или литерал"; return(true); } } error = "Невалидна инструкция"; return(false); }
public override bool Verify(string[] lines, TheCpu cpu, out string error) { if (lines.Length > 0) { if (lines[0].ToUpper() != commandString) { error = "Невалидна инструкция"; return(false); } } if (lines.Length == 2) { if (cpu.ValidRegister(lines[1])) { // CMD sX error = null; return(true); } else { error = "Първият аргумент на инструкцията трябва да е регистър"; return(true); } } error = "Невалидна инструкция"; return(false); }
public override bool Verify(string[] lines, TheCpu cpu, out string error) { if (lines.Length > 0) { if (lines[0].ToUpper() != "NAMEREG") { error = "Невалидна инструкция"; return(false); } } if (lines.Length > 1) { if (!lines[1].EndsWith(",")) { error = "Липсваща запетайка"; return(true); } if (!cpu.ValidRegister(lines[1].Remove(lines[1].Length - 1))) { error = "Първият аргумент на инструкцията трябва да е регистър"; return(true); } } if (lines.Length == 3) { // NAMEREG sY, name var register = lines[1].Remove(lines[1].Length - 1).ToLower(); var name = lines[2].ToLower(); if (cpu.NamedRegisters.ContainsKey(name)) { cpu.NamedRegisters[name] = register; } else { cpu.NamedRegisters.Add(name, register); } error = null; return(true); } error = "Невалидна инструкция"; return(false); }
public override void Execute(string[] lines, TheCpu cpu) { if (cpu.ValidRegister(lines[2])) { // CMD sX, sY this.ExecuteV1(lines[1].Remove(lines[1].Length - 1), lines[2], cpu); } else if (cpu.ValidLiteral(lines[2])) { // CMD sX, kk this.ExecuteV2(lines[1].Remove(lines[1].Length - 1), lines[2], cpu); } else { throw new ArgumentException("Невалидна инструкция."); } }
public override void Execute(string[] lines, TheCpu cpu) { var parameter1 = lines[1].Remove(lines[1].Length - 1); var parameter2 = lines[2].Replace("(", "").Replace(")", "").Trim(); if (cpu.ValidRegister(parameter2)) { // CMD sX, sY this.ExecuteV1(parameter1, parameter2, cpu); } else if (cpu.ValidLiteral(lines[2])) { // CMD sX, kk this.ExecuteV2(parameter1, lines[2], cpu); } else { throw new ArgumentException("Невалидна инструкция."); } }