7

Is there a program that will convert assembly to C or C++? I did a lot of searching but I could not find anything that works. There is a program called "Boomerang"; it looks great and just want I wanted, but it's very unstable and crashes when I try to use it. (boomerang)

Are there any other free programs that will do that?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
blood
  • 746
  • 5
  • 13
  • 22

3 Answers3

2

What you're looking for is a decompiler.

You will end up with something not really much better than the ASM source, and I'm pretty sure you're going to end up with C, not C++ anyway.

thomasfedb
  • 5,990
  • 2
  • 37
  • 65
  • 2
    i don't think i want a decompiler, i have the assembly code but i want it turned into c++. – blood Jul 13 '10 at 19:40
1

There are few tools able to do the conversion like Regolix translator from ASM to C and Datatek converting ASM to C/C++/Cobol/C#. However, I think the maintenance of the converted code can be problematic.

zoli2k
  • 3,388
  • 4
  • 26
  • 36
  • yea i looked at both of thoses Relogix i don't understand i think it's built in and idk how to use it. and datatek you have to pay for it. i looked but i did not see anything about downloading you have to call them to talk about buying. – blood Jul 13 '10 at 19:36
0

This is not possible.

It cannot be done.

It is beyond the grasp of mortals.

Well, unless the C code uses embedded assembly. But even there it's a little iffy.

Note that a decompiler does not "convert assembly to C". A decompiler attempts to approximate a program's original source code. The mapping is not necessarily perfect, and not possible for arbitrary assembly (again, unless you use inline assembly in the resulting C).

Borealid
  • 95,191
  • 9
  • 106
  • 122
  • 1
    Eh? No... it won't be perfect, but getting it to be at least a little bit higher level so it's easier to work with is still a good start. – mpen Jul 13 '10 at 05:36
  • 1
    -1 The maintenance of the decompiled code can be difficult but it can be done. – zoli2k Jul 13 '10 at 05:40
  • 2
    @zoli2k: no, for arbitrary assembly, it cannot be done. The capabilities of C are not a loose superset of those of assembly language. For example, let's say my assembly consists of "TST %r1". This instruction causes the processor step counter to go up by 1, but if I don't use the result, has no other effect. There is no C code which equates to this lone instruction. There are many other examples - reading processor internal registers, writing to I/O devices directly, even the HLT instruction. What I said was correct. – Borealid Jul 13 '10 at 05:43
  • @Borealid, in sample conversions of Regolix there are also converted TST instructions. I absolutely agree with you, that writing that ASM is a different level of control over the hardware than C and some instructions can not be directly converted to C. On the other hand, if a tool is able to convert only 90% of the ASM code to C, that is already a lot of saved time. I will remove -1 if you add your examples with HLT and TST to the answer. – zoli2k Jul 13 '10 at 06:02
  • 2
    @zoli2k: An easy example is a function which consists of 10 HLT instructions. This has no C equivalent. Ditto one consisting of 10 "TST %r1". Or, for instance, a program with no functions at all (see http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html ). Just because the disassembler can find equivalents for *some* code containing the instructions does not mean it can do so for *all* uses of the instructions. And what the poster asked for was a converter - i.e. an invertible mapping. – Borealid Jul 13 '10 at 06:09
  • Can you add this to your answer so I can remove the vote down? – zoli2k Jul 13 '10 at 06:23
  • 3
    The funny thing is, for the game Transport Tycoons Deluxe (aka TTD), this very thing was done. Yes, it contained tons of `TST %r1` instructions. So? That just meant the decompiler emitted a macro. – MSalters Jul 13 '10 at 07:46