Re:Show HN: Assembly to C code Decompiler
by Frondo on Friday May 27, 2016 @02:31PM
(#11787920)
I'd be curious to see what C it produced if you fed it hand-written assembly.
[ Parent
| on HN ]
Decompilers don't promise to recreate the original C code; they just promise to transform assembly instructions into some kind of C program.
Re:Show HN: Assembly to C code Decompiler
by colejohnson66 on Friday May 27, 2016 @10:47PM
(#11790389)
Decompilers don't "deoptimize" programs. Compilation is a very lossy process (reused variables, moving variables to other registers, etc.). The best you'll get is some C code that, when compiled, would do the same thing as the original assembly (but probably slower). Interesting idea, nonetheless.
The game that I mentioned elsewhere in this thread seems to be a mix of C and assembly (as one would expect from an early-90s game), so I'd be curious about the same thing.
Many instructions of machine code can be written as one C statement. There are some cases of things the cpu can do that are not standardized in C, like "arithmetic shift vs. logical shift." Maybe these instructions would be inlined.
> Many instructions of machine code can be written as one C statement.
I'm quite aware =) Nested loops, some pointer calculations (dealing with real mode pointers), conditionals with more than one condition, and multi-step math statements seem particularly verbose, compared to their higher-level equivalents. If a piece of code gets kind of complicated, I usually hand-decompile it, and it's usually much shorter, even in fairly-naive C code.