Esempio n. 1
0
        public ProgramSource GenerateProgramSource()
        {
            var ps = new ProgramSource();

            foreach (KeyValuePair <string, byte[]> data in _assembly.Data)
            {
                GenerateDataEntry(ps, data.Key, data.Value);
            }
            foreach (KeyValuePair <string, int> constant in _assembly.Constants)
            {
                ps.AddCodeLine("var ", constant.Key, " = 0x", constant.Value.ToString("X"));
            }

            ps.AddLine("goto _start;");

            foreach (X86AssemblySection section in _assembly.Sections)
            {
                ps.AddLine(_assembly.InternalNameOf(section.Name) + ":");

                if (section.InstructionCount == 0)
                {
                    ps.AddLine(";");
                }
                else
                {
                    foreach (X86Instruction instruction in section.Instructions)
                    {
                        InstructionCodeGenerator.Generate(ps, _assembly, instruction);
                    }
                }
            }

            return(ps);
        }
        public ProgramSource GenerateProgramSource()
        {
            var ps = new ProgramSource();
            foreach (KeyValuePair<string, byte[]> data in _assembly.Data)
            {
                GenerateDataEntry(ps, data.Key, data.Value);
            }
            foreach (KeyValuePair<string, int> constant in _assembly.Constants)
            {
                ps.AddCodeLine("var ", constant.Key, " = 0x", constant.Value.ToString("X"));
            }

            ps.AddLine("goto _start;");

            foreach (X86AssemblySection section in _assembly.Sections)
            {
                ps.AddLine(_assembly.InternalNameOf(section.Name) + ":");

                if (section.InstructionCount == 0)
                    ps.AddLine(";");
                else
                    foreach (X86Instruction instruction in section.Instructions)
                    {
                        InstructionCodeGenerator.Generate(ps, _assembly, instruction);
                    }
            }

            return ps;
        }
Esempio n. 3
0
 public static void GenerateCmp(ProgramSource ps, string value1, string value2)
 {
     ps.AddLine("{");
     {
         ps.AddLine("ulong temp = (ulong)(" + value1 + ") - (ulong)(" + value2 + ");", 1);
         ps.AddLine("SF = ((0x80000000 & temp) != 0) ? 1 : 0;", 1);
         ps.AddLine("ZF = (temp == 0) ? 1 : 0;", 1);
         ps.AddLine("var signedResult = (long) temp;", 1);
         ps.AddLine("OF = (signedResult > int.MaxValue || signedResult < int.MinValue) ? 1 : 0;", 1);
     }
     ps.AddLine("}");
 }
 public static void GenerateCmp(ProgramSource ps, string value1, string value2)
 {
     ps.AddLine("{");
     {
         ps.AddLine("ulong temp = (ulong)(" + value1 + ") - (ulong)(" + value2 + ");", 1);
         ps.AddLine("SF = ((0x80000000 & temp) != 0) ? 1 : 0;", 1);
         ps.AddLine("ZF = (temp == 0) ? 1 : 0;", 1);
         ps.AddLine("var signedResult = (long) temp;", 1);
         ps.AddLine("OF = (signedResult > int.MaxValue || signedResult < int.MinValue) ? 1 : 0;", 1);
     }
     ps.AddLine("}");
 }