private byte[] StringToMachineCode(string _input, Dictionary <string, int> _labels) { bool _debug = false; byte[] instruction = new byte[8]; instruction[0] = 0x00; //NULL opcode instruction[1] = 0x01; //Reference type Literal instruction[2] = 0x00; //Data upper byte instruction[3] = 0x00; //Data lower byte instruction[4] = 0x01; //Reference type Literal instruction[5] = 0x00; //Data upper byte instruction[6] = 0x00; //Data lower byte instruction[7] = 0xFF; //RESERVED byte List <string> tokens = tokenizeLine(_input); if (_debug) { Console.WriteLine("Raw:\n" + _input); Console.WriteLine("Tokenized:"); foreach (string t in tokens) { Console.Write(" | " + t); } Console.WriteLine(" |"); Console.ReadLine(); } AssemblyTable table = new AssemblyTable(); instruction[0] = table.GetOpcode(tokens[0]); if (tokens.Count >= 2) { byte[] b = ParseArgument(tokens[1], _labels); instruction[1] = b[0]; instruction[2] = b[1]; instruction[3] = b[2]; if (tokens.Count >= 3) { b = ParseArgument(tokens[2], _labels); instruction[4] = b[0]; instruction[5] = b[1]; instruction[6] = b[2]; if (tokens.Count > 3) { throw new Exception("Too many parameters"); } } } return(instruction); }
private byte[] StringToMachineCode(string _input, Dictionary<string, int> _labels) { bool _debug = false; byte[] instruction = new byte[8]; instruction[0] = 0x00; //NULL opcode instruction[1] = 0x01; //Reference type Literal instruction[2] = 0x00; //Data upper byte instruction[3] = 0x00; //Data lower byte instruction[4] = 0x01; //Reference type Literal instruction[5] = 0x00; //Data upper byte instruction[6] = 0x00; //Data lower byte instruction[7] = 0xFF; //RESERVED byte List<string> tokens = tokenizeLine(_input); if (_debug) { Console.WriteLine("Raw:\n" + _input); Console.WriteLine("Tokenized:"); foreach (string t in tokens) { Console.Write(" | " + t); } Console.WriteLine(" |"); Console.ReadLine(); } AssemblyTable table = new AssemblyTable(); instruction[0] = table.GetOpcode(tokens[0]); if (tokens.Count >= 2) { byte[] b = ParseArgument(tokens[1], _labels); instruction[1] = b[0]; instruction[2] = b[1]; instruction[3] = b[2]; if (tokens.Count >= 3) { b = ParseArgument(tokens[2], _labels); instruction[4] = b[0]; instruction[5] = b[1]; instruction[6] = b[2]; if (tokens.Count > 3) { throw new Exception("Too many parameters"); } } } return instruction; }