Assembler to C converter for PIC?

Hi All, Has anybody heard of an assembly to C converter tool for Microchip PICs. A Converter from MPASM to C, or is it impossible? Thanks

Reply to
booth multiplier
Loading thread data ...

Only if you convert it from a hex file to asm or c i'll call it reverse engineering......

SFC

schreef in bericht news: snipped-for-privacy@l41g2000cwc.googlegroups.com...

Reply to
SFC

Indeed. Converting from assembler to C is more like gambling....

Meindert

Reply to
Meindert Sprang

It's easy .. if using the CCS PIC compiler, the following example ...

int count; #asm movlw 0x8 movwf count #endasm

or in other flavors of "C" asm("assembly_lang_statment");

Sorry -- I couldn't resist ;-) You mean that was not what he meant ??

mikey

Reply to
Mike Fields

I meant something like this:

transforms to:

count=8;

I was asking for a MPASM to C translator not for a Decompiler. I thought it would be not so hard as MPASM has a specific Syntax.

Reply to
booth multiplier

All C compilers convert the code via assembly language. The stage may not be externally viewable, but it's there anyway. This is the compilation process. It loses very much information of the original C code, and all the information cannot be automatically restored.

The process of converting from machine code (hex, binary, or whatever format) to assembly language is much simpler, and it can be for the most part performed automatically. This process is usually called dis-assembly. Even here much of the information in the original code is missing and has to be manually re-created.

The specific syntax and semantics of assembly language helps very little in the whole picture of re-creating the lost information needed to reconstruct the C source.

Your example is one of the easiest parts in a decompilation process. Try again with some optimized loops with array addressing to see the larger picture. The whole decompilation process is like solving a cross-word puzzle.

Been there - done that.

--

Tauno Voipio
tauno voipio (at) iki fi
Reply to
Tauno Voipio

Send me a private email with contact information. We may be able to help you.

w..

booth multiplier wrote:

Reply to
Walter Banks

This thread seems to be arguing over what's possible (and what you describe IS called a decompiler), but there's plenty of info on Usenet as well as the Web, as you'll find if you search for: assembly C decompiler (see weblinks below)

My short-to-medium answer is yes, sort of, it's possible for a program to read a particular assembly (or equivalently, machine) language and spit out a C program that does the same thing, but: 1) the code compiled from that C program will surely be larger and slower than the original machine/assembly code, and 2) it may not really be any more readable than the assembly code. Code such as this (6502):

ldx 10d label005: jsr sub003 dex bne label005

through a decompiler might look like this:

int register_x; register_x = 10; label005: sub003(); registerx--; if (registerx != 0) goto label005;

You rarely see labels and goto's in C, but that would be the most straightforward (easiest for the decompiler writer) way of translating it. Such a translator could generate 'for' and 'while' statements, but that would mean recognizing several assembly statements as being equivalent to such a high-level statement. Such things can be done (this might be called an 'optimizing deompiler', but it might be only marginally helpful. If your assembly is hand-written with comments and labels that make sense in the context of the program, a decompiler could (and should) pick these up and put them in the appropriate places of the C code.

Google searches bring up lots of threads and discussion, mostly for x86, though I saw a mention of 8051. I didn't look specifically for PIC. Many references were about writing such a decompiler such as this one:

formatting link

Here's a neat webpage showing 'original' C code on the left and after compiling and running through the decompiler, apparently for x86:

formatting link

Does that (the C code on the right) look like the kind of output you were thinking of?

If you think that's usable, do a search-engine search for a PIC decompiler.

Sorry you asked yet? :-)

-----

formatting link

Reply to
Ben Bradley

I would like to know whose code are you trying to steal ???

Reply to
hamilton

This is not about stealing nor converting machine language to C. Its about upgrading and Education. The tool will help:

  1. Students who start with C and want to use HANDWRITTEN Assembly Examples on the Net.
  2. Assembly coders who want to upgrade their code to C. Is this not worth asking for?

Thanks Anyway

Reply to
booth multiplier

Students are much better off doing that conversion manually --- they'll learn a great deal about that particular C compiler, assembler and micro in the process, which is what being a student is supposedly all about.

Why would they ever want to do that? If the assembly program was written by people worthy of being called "assembly coders", odds are that a direct translation to C would be vastly inferior to a plain rewrite from scratch.

In other words, the only tools actually *needed* for such a conversion are lots of documentation, time and a screen large enough to display C and assembly source side-by-side. Or failing the latter, a paper print-out holder to sit next to the screen.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

assembler

I'm a student and I'd get confused as ever going from assembler to C. I tried that eons ago with Z80 stuff and it's a confusing bloated layer of bizzaro labels and gotos. Don't foist that upon your students unless you want them to leave.

Much better, as Hans said, is to learn assembler, learn C, and how to convert from one to another. I'm trying C2Cplus (formerly picant) and it will generate heavily commented (corresponding to C source) assembler (their SourceboostC steps in C source) which makes comparisons between C and assembler easy, and for newbies, enlightening.

I don't know squat about 16F assembler, but at 35 instructions, it's not bad. It is actually fun (only 35 instructions) to examine small listings to see how people solve problems. It could likely be essential to learn and write assembler for certain projects.

Portability?

Reply to
John

Relogix

formatting link
performs assembler-to-C tranlation for 680x0 and 80x86 CPUs. The vendor offers porting services for other architectures.

-- Dan Henry

Reply to
Dan Henry

If you were an educator, you would already understand compiler theory.

Getting the "original" C code from assembly in not possible.

The best you can get is a (dare I say it) is a flow of the program.

From there you can 're-engineer' the code in C.

My guess is that you are not an educator.

Reply to
hamilton

OK, I know I'm very late to the party! However I just noticed that our web log shows a recent entry for visitor who reached our site via this thread, so I'll add this comment in case anyone else follows...

You can do much better than obtaining a "flow of program" as suggested by the previous post, although it's tricky to do so.

Our company, MicroAPL, has a software tool called Relogix which reverse-engineers assembly code and produces C. We aim to get close to what a human programmer might write - i.e. readable, maintainable code.

To judge how well we do, take a look at some of the examples on our web site. These are all automatic translations produced by Relogix, before our engineers perform a post-translation cleanup.

The link is:

formatting link

--------------------------------------- Posted through

formatting link

Reply to
Simon Marsden

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.