Пример #1
0
        public string Disassemble(byte[] _binary)
        {
            string output = "";

            List <byte[]> lines = new List <byte[]>();

            //Split the program into instruction lines
            for (int i = 0; i < _binary.Length; i += 8)
            {
                byte[] temp = new byte[8];
                temp[0] = _binary[i];       //Opcode
                temp[1] = _binary[i + 1];   //Parameter mode
                temp[2] = _binary[i + 2];   //Upper byte
                temp[3] = _binary[i + 3];   //Lower byte
                temp[4] = _binary[i + 4];   //Parameter mode
                temp[5] = _binary[i + 5];   //Upper byte
                temp[6] = _binary[i + 6];   //Lower byte
                temp[7] = _binary[i + 7];   //0xFF
                lines.Add(temp);
            }

            foreach (byte[] line in lines)
            {
                string        assemblyLine = "";
                AssemblyTable table        = new AssemblyTable();
                //Does it look like an instruction?
                if (line[7] == 0xFF && table.ContainsOpcode(line[0]))
                {
                    //It's probably an instruction. Translate it!
                    assemblyLine += table.GetInstruction(line[0]) + " "; //Opcode to command. Easy.

                    byte[] parameter = new byte[3];
                    parameter[0]  = line[1];
                    parameter[1]  = line[2];
                    parameter[2]  = line[3];
                    assemblyLine += machineCodeToParameter(parameter);

                    if ((line[4] | line[5] | line[6]) != 0x00)
                    {
                        parameter[0]  = line[4];
                        parameter[1]  = line[5];
                        parameter[2]  = line[6];
                        assemblyLine += " " + machineCodeToParameter(parameter);
                    }
                    assemblyLine += "\t# " + ByteArrayToString(line);
                }
                else
                {
                    //It's not an instruction, but insert it as a comment
                    assemblyLine = "# Unknown Data:" + ByteArrayToString(line);
                }

                Console.WriteLine(assemblyLine);
                output += (assemblyLine + "\n");
            }

            return(output);
        }
Пример #2
0
        override public string ToString()
        {
            string        result = "";
            AssemblyTable table  = new AssemblyTable();

            result += table.GetInstruction(Opcode);
            result += "," + ByteArrayToString(Argument1);
            result += "," + ByteArrayToString(Argument2);
            return(result);
        }
Пример #3
0
        public string Disassemble(byte[] _binary)
        {
            string output = "";

            List<byte[]> lines = new List<byte[]>();

            //Split the program into instruction lines
            for (int i = 0; i < _binary.Length; i += 8)
            {
                byte[] temp = new byte[8];
                temp[0] = _binary[i];       //Opcode
                temp[1] = _binary[i + 1];   //Parameter mode
                temp[2] = _binary[i + 2];   //Upper byte
                temp[3] = _binary[i + 3];   //Lower byte
                temp[4] = _binary[i + 4];   //Parameter mode
                temp[5] = _binary[i + 5];   //Upper byte
                temp[6] = _binary[i + 6];   //Lower byte
                temp[7] = _binary[i + 7];   //0xFF
                lines.Add(temp);
            }

            foreach (byte[] line in lines)
            {
                string assemblyLine = "";
                AssemblyTable table = new AssemblyTable();
                //Does it look like an instruction?
                if (line[7] == 0xFF && table.ContainsOpcode(line[0]))
                {
                    //It's probably an instruction. Translate it!
                    assemblyLine += table.GetInstruction(line[0]) + " "; //Opcode to command. Easy.

                    byte[] parameter = new byte[3];
                    parameter[0] = line[1];
                    parameter[1] = line[2];
                    parameter[2] = line[3];
                    assemblyLine += machineCodeToParameter(parameter);

                    if ((line[4] | line[5] | line[6]) != 0x00)
                    {
                        parameter[0] = line[4];
                        parameter[1] = line[5];
                        parameter[2] = line[6];
                        assemblyLine += " " + machineCodeToParameter(parameter);
                    }
                    assemblyLine += "\t# " + ByteArrayToString(line);
                }
                else
                {
                    //It's not an instruction, but insert it as a comment
                    assemblyLine = "# Unknown Data:" + ByteArrayToString(line);
                }

                Console.WriteLine(assemblyLine);
                output += (assemblyLine + "\n");
            }

            return output;
        }
Пример #4
0
 public override string ToString()
 {
     string result = "";
     AssemblyTable table = new AssemblyTable();
     result += table.GetInstruction(Opcode);
     result += "," + ByteArrayToString(Argument1);
     result += "," + ByteArrayToString(Argument2);
     return result;
 }