Can hex be converted?

Discussion in 'Embedded Systems and Microcontrollers' started by KrashKaloop, Aug 26, 2008.

  1. KrashKaloop

    Thread Starter New Member

    Aug 26, 2008
    I am completely new to programming PICs and need some advice.

    I have a device that uses a PIC16F876A, and I am trying to do some modifications to the code which was written in PICBasic Pro. This is an open source project, so I have both the hex and Basic code that the device currently runs on.

    I also have downloaded MPLAB and have been familiarizing myself with it. I have also purchased a PIC programmer which I hope will suit my needs. This is the programmer I bought from futurlec.

    Although I know if I purchased PICBasic Pro, I could use it to modify the existing code, I was wondering if I could just use the MPLABS to do the same thing. Is it possible to convert the hex code (produced in PICBasic pro), and convert it into one of the languages supported in MPLAB?

    Or is there a way to use MPLAB to program in the same language as PICBasic Pro? I just don’t want to spend the money for PICBasic Pro to modify a single PIC for use in a hobby project.

    I hope I explained this sufficiently. Thanks
  2. kammenos

    Active Member

    Aug 3, 2008

    What exactly do you mean? Can you give an example?:confused::confused::confused:
  3. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
  4. RiJoRI

    Well-Known Member

    Aug 15, 2007
    A disassembler will convert from hex to assembly. To go from assembly to BASIC, Pascal, C, or any other language is for all intents and purposes impossible. The problem is that given a set of assembly instructions, how does a program figure out what the HLL should be?
    Code ( (Unknown Language)):
    2.     DECSZ   _bpnt.W
    3.     JP  .+0x1
    4.     LD  X,_bpnt.W
    5.     LD  A,_parttn.B
    6.     ST  A,[X].B
    We can all see what is happening, but nobody can back-translate this to the original code:"push(Parameter,parttn)"

    Again, if the change is simple enough, or the program is VERY simple, you may be able to patch the code.


    (For the curious, the assembly code is for a NatSemi HPC16083 chip.)
  5. jpanhalt

    AAC Fanatic!

    Jan 18, 2008

    I think that is what he wants. He has the hex and Basic code already, but apparently not a Basic compiler. John
  6. SgtWookie


    Jul 17, 2007
    It would be far easier to translate the Basic source code to another language than to dissasemble the hex code and try to make sense out of it.

    The Basic compiler would have made heavy use of library functions, and quite probably optimization routines. If you made changes in the original Basic source and recompiled it, the output hex file may look quite different from the current file, due to selection of different optimization techniques.

    Disassemblers have no good way to determine what is program space, and what is data space. With reasonably sophisticated disassemblers, you can run them in an iterative process, adding labels for branch points and data areas, until you can make some sense out of the code. With unsophisticated disassemblers, you are basically left in the dark.

    A simple disassembly listing really isn't much help. You really need the offset list and link list from the compiliation process to help you determine the labels and data areas.
  7. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    It really depends on what you need to do. A couple of years back, I had a lab instrument that was no longer supported by the manufacturer. Some of the names and constants needed updating. I was able to disassemble it, change only the few things that needed changing (changing constants, changing names, but not changing the fundamental calculations), and it worked fine. Of course, to completely reverse engineer the program would have been a very difficult task.

    My impression was that the OP had a similar need to tweak the program.