public static RET Create(ILineInfo line) { if (line.NumberOfArguments > 1) { throw new Exceptions.ArgumentNumberException("RET", line.NumberOfArguments); } var cmd = new RET() { LineNumber = line.LineNumber }; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Number: cmd.Argument1 = new Number((Int16)line.ArgumentAsNumber(1)); cmd.Assemble = cmd.assemble; break; case Lexer.ArgumentType.None: cmd.Assemble = cmd.assemble; break; } if (cmd.Assemble == null) { throw new Exceptions.ArgumentException("RET", line.TypeOfArgument(1)); } return(cmd); }
public static DEC Create(ILineInfo line) { if (line.NumberOfArguments != 1) { throw new Exceptions.ArgumentNumberException("DEC", line.NumberOfArguments); } var cmd = new DEC() { LineNumber = line.LineNumber }; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Register: cmd.Argument1 = new Register(line.Argument(1)); cmd.Assemble = cmd.assembleR; break; case Lexer.ArgumentType.Name: case Lexer.ArgumentType.Indirect: cmd.Argument1 = new MemoryIndirect( line.NameInArgument(1), line.RegistersInArgument(1), line.NumbersInArgument(1), line.LastCapture ); cmd.Assemble = cmd.FactoryAssemble(0xfe); break; } if (cmd.Assemble == null) { throw new Exceptions.ArgumentException("DEC", line.TypeOfArgument(1)); } return(cmd); }
public static INT Create(ILineInfo line) { if (line.NumberOfArguments != 1) { throw new Exceptions.ArgumentNumberException("INT", line.NumberOfArguments); } var cmd = new INT() { LineNumber = line.LineNumber }; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Number: cmd.Argument1 = new Number((Int16)line.ArgumentAsNumber(1)); if (cmd.Argument1.IsWord) { throw new Exceptions.ArgumentSizeException("INT"); } cmd.Assemble = cmd.assemble; break; } if (cmd.Assemble == null) { throw new Exceptions.ArgumentException("INT", line.TypeOfArgument(1)); } return(cmd); }
public static CALL Create(ILineInfo line) { if (line.NumberOfArguments != 1) { throw new Exceptions.ArgumentNumberException("CALL", line.NumberOfArguments); } var cmd = new CALL() { LineNumber = line.LineNumber }; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Name: cmd.ProcedureName = line.Argument(1).ToLower(); cmd.Capture = line.LastCapture; cmd.Assemble = cmd.assemble; break; } if (cmd.Assemble == null) { throw new Exceptions.ArgumentException("CALL", line.TypeOfArgument(1)); } return(cmd); }
public static Jxx Create(ILineInfo line) { var command = line.Command.ToUpper(); if (line.NumberOfArguments != 1) { throw new Exceptions.ArgumentNumberException(command, line.NumberOfArguments); } var cmd = new Jxx() { LineNumber = line.LineNumber, CommandName = command }; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Name: cmd.LabelName = line.Argument(1).ToLower(); cmd.Capture = line.LastCapture; cmd.Assemble = cmd.assemble; break; } if (cmd.Assemble == null) { throw new Exceptions.ArgumentException(command, line.TypeOfArgument(1)); } return(cmd); }
public static PUSH Create(ILineInfo line) { if (line.NumberOfArguments != 1) { throw new Exceptions.ArgumentNumberException("PUSH", line.NumberOfArguments); } var cmd = new PUSH() { LineNumber = line.LineNumber }; bool isMem = false; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Register: cmd.Argument1 = new Register(line.Argument(1)); cmd.Assemble = cmd.assembleR; break; case Lexer.ArgumentType.Number: cmd.Argument1 = new Number((Int16)line.ArgumentAsNumber(1)); cmd.Assemble = cmd.assembleI; break; case Lexer.ArgumentType.Name: case Lexer.ArgumentType.Indirect: cmd.Argument1 = new MemoryIndirect( line.NameInArgument(1), line.RegistersInArgument(1), line.NumbersInArgument(1), line.LastCapture ); isMem = true; cmd.Assemble = cmd.assembleM; break; } if (cmd.Assemble == null) { throw new Exceptions.ArgumentException("PUSH", line.TypeOfArgument(1)); } if (!isMem) { cmd.CheckArgumentSize(); } return(cmd); }
public static LEA Create(ILineInfo line) { if (line.NumberOfArguments != 2) { throw new Exceptions.ArgumentNumberException("LEA", line.NumberOfArguments); } var cmd = new LEA() { LineNumber = line.LineNumber }; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Register: cmd.Argument1 = new Register(line.Argument(1)); if (!cmd.Argument1.IsWord) { // TODO: make better exception throw new Exceptions.ArgumentSizeException("LEA"); } switch (line.TypeOfArgument(2)) { case Lexer.ArgumentType.Name: cmd.Argument2 = new MemoryName(line.Argument(2), line.LastCapture); cmd.Assemble = cmd.assembleRM; break; } break; } if (cmd.Assemble == null) { // need better exception ? throw new Exceptions.ArgumentException("LEA", line.TypeOfArgument(1), line.TypeOfArgument(2)); } return(cmd); }
public static MOV Create(ILineInfo line) { if (line.NumberOfArguments != 2) { throw new Exceptions.ArgumentNumberException("MOV", line.NumberOfArguments); } var cmd = new MOV() { LineNumber = line.LineNumber }; bool isMem = false; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Register: cmd.Argument1 = new Register(line.Argument(1)); switch (line.TypeOfArgument(2)) { case Lexer.ArgumentType.Register: cmd.Argument2 = new Register(line.Argument(2)); cmd.Assemble = cmd.FactoryAssemble(0x88); //cmd.assembleRR; break; case Lexer.ArgumentType.Number: cmd.Argument2 = new Number((Int16)line.ArgumentAsNumber(2)); cmd.Assemble = cmd.assembleRI; //cmd.FactoryAssemble(0xc6); break; case Lexer.ArgumentType.Name: case Lexer.ArgumentType.Indirect: cmd.Argument2 = new MemoryIndirect( line.NameInArgument(2), line.RegistersInArgument(2), line.NumbersInArgument(2), line.LastCapture ); cmd.Assemble = cmd.FactoryAssemble(0x8a); //cmd.assembleRM; isMem = true; break; } break; case Lexer.ArgumentType.Name: case Lexer.ArgumentType.Indirect: cmd.Argument1 = new MemoryIndirect( line.NameInArgument(1), line.RegistersInArgument(1), line.NumbersInArgument(1), line.LastCapture ); isMem = true; switch (line.TypeOfArgument(2)) { case Lexer.ArgumentType.Register: cmd.Argument2 = new Register(line.Argument(2)); cmd.Assemble = cmd.FactoryAssemble(0x88); //cmd.assembleMR; break; case Lexer.ArgumentType.Number: cmd.Argument2 = new Number((Int16)line.ArgumentAsNumber(2)); cmd.Assemble = cmd.FactoryAssemble(0xc6); //cmd.assembleMI; break; } break; } if (cmd.Assemble == null) { var lastCapture = line.LastCapture; throw new Exceptions.ArgumentException("MOV", line.TypeOfArgument(1), line.TypeOfArgument(2), lastCapture); } if (!isMem) { cmd.CheckArgumentSize(); } return(cmd); }
public static IMUL Create(ILineInfo line) { if (line.NumberOfArguments == 0 || line.NumberOfArguments > 2) { throw new Exceptions.ArgumentNumberException("IMUL", line.NumberOfArguments); } var cmd = new IMUL() { LineNumber = line.LineNumber }; bool isMem = false; switch (line.TypeOfArgument(1)) { case Lexer.ArgumentType.Register: cmd.Argument1 = new Register(line.Argument(1)); switch (line.TypeOfArgument(2)) { case Lexer.ArgumentType.None: cmd.Assemble = cmd.FactoryAssemble1(0xf6); break; case Lexer.ArgumentType.Register: cmd.Argument2 = new Register(line.Argument(2)); cmd.Assemble = cmd.FactoryAssemble2(0xaf, 0x0f); break; case Lexer.ArgumentType.Name: case Lexer.ArgumentType.Indirect: cmd.Argument2 = new MemoryIndirect( line.NameInArgument(2), line.RegistersInArgument(2), line.NumbersInArgument(2), line.LastCapture ); isMem = true; cmd.Assemble = cmd.FactoryAssemble2(0xaf, 0x0f); break; case Lexer.ArgumentType.Number: cmd.Argument2 = new Number((Int16)line.ArgumentAsNumber(2)); cmd.Assemble = cmd.FactoryAssemble2(0x69); break; } break; case Lexer.ArgumentType.Name: case Lexer.ArgumentType.Indirect: cmd.Argument1 = new MemoryIndirect( line.NameInArgument(1), line.RegistersInArgument(1), line.NumbersInArgument(1), line.LastCapture ); isMem = true; switch (line.TypeOfArgument(2)) { case Lexer.ArgumentType.None: cmd.Assemble = cmd.FactoryAssemble1(0xf6); break; } break; } if (cmd.Assemble == null) { var lastCapture = line.LastCapture; throw new Exceptions.ArgumentException("IMUL", line.TypeOfArgument(1), line.TypeOfArgument(2), lastCapture); } if (!isMem) { cmd.CheckArgumentSize(); } return(cmd); }