MPLAB And Hex Listing To Hex Executable

Discussion in 'Embedded Systems and Microcontrollers' started by waynerr, Dec 16, 2015.

  1. waynerr

    Thread Starter New Member

    Jun 21, 2009
    5
    0
    Hello,

    I found a .hex listing on the web. I would like to convert to a .hex executable to use to program a 16F628A.
    The only way I can figure to work with the listing is as a .txt file. I cannot figure to do from .hex listing to .hex executable.
    I have tried MPLAB in .asm and XC8.
    I open a project, open a source file and erase everything in the file then copied-and-pasted the .hex listing .txt into the file I do a Clean-Build. It does not work.
    I would type the details of the faults and error, I am trying to first make this as short as possible. Can someone suggest how I might be going down the wrong road ? Any help is Gratefully appreciated.

    Thanks,

    Wayne​
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    Compilers and assemblers are not designed to take a "listing" file as input and build an executable. You might be able to write a filter to process the listing file into a usable source file. It might also take you less time to actually reenter the source file from scratch. It is also possible that I don't understand what a .hex listing file is. Could you provide an example of a dozen lines, so I can verify my inferences.
     
  3. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    The .hex file can be 'imported' directly into MPLAB for chip programming. No project. No build.

    Use <F>ile, <I>mport.

    You will need to select the device prior to programming, and, perhaps, the proper configuration bits if they are not set in the .hex file.
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    I believe there is a difference between a .hex file encoded to the intel standard, where each line begins with a colon and ends with a checksum, and ".hex listing file" which has the location counter the contents of the instruction bytes or words followed by the source code. If he is talking about the first kind then I agree with you, but I fear he is talking about the second kind. Admittedly, I have no idea what a .hex executable might be, but I think it refers to what you are thinking of.
     
  5. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    He said .hex. A 'list' file is .lst. Aside from the rest of his text, which clearly illustrates his confusion, I took the file extension as the "factual" part of his post.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    That is not correct. He said:

    I found a .hex listing on the web. I would like to convert to a .hex executable to use to program a 16F628A.


    The TS/OP is clearly talking about two different files here. We will see whose interpretation is correct if he provides the example I requested. For all I know you are correct and he tried to compile(assemble) a .hex file.
     
    Last edited: Dec 16, 2015
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Irregardless of what the OP said a .hex file is an executable file when uploaded into the device it is intended. No translation required beyond the programming software and hardware.

    However, if the '628A is not the build target of that .hex then the OP has some reverse engineering work to do.
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    You know that, and joey knows that, and even I know that; but clearly the TS/OP does not quite seem to know what he is or is not talking about. Let me draw one further inference. Why would anybody post a .hex file on the web in such a way that anybody would think that you needed to run it through a compiler or assembler to build it. I could see that for a listing file with printable hexadecimal numbers in it. I think you're putting way to much weight on the use of ".hex" as a modifier to "listing file". We really need the TS/OP to shoot us an example of his ".hex listing file".
     
  9. waynerr

    Thread Starter New Member

    Jun 21, 2009
    5
    0
     
  10. waynerr

    Thread Starter New Member

    Jun 21, 2009
    5
    0
    Thank you for all the replies and information. I was not sure I could do this, but I now have permission from the software creator to use the listing as I wish. This is a link to the page with the .hex code. I am asking how to use this to create a file I can use ?

    https://sites.google.com/site/vk3bhr/home/index2-html/lc2a-hex

    I am sorry I know just to be dangerous

    Thanks,

    Wayne
     
  11. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Never used it but I believe you can use the IPE application in XC8 for this..
     
  12. JohnInTX

    Moderator

    Jun 26, 2012
    2,339
    1,022
    Here you go.
    All I did was highlight the Intel HEX portion of the listing and paste it to a file in Notepad.

    Use File->Import to load it (MPLAB 8.x)
    You still have to tell it what PIC you are using and fixup the config bits.

    You can recover an a version of the source by:
    View->Program Memory
    Select the Machine Tab to disassemble the hex image to a listing.
    Right click in the window and select Output to File. Name it I2Ca.asm
    You now have a text file with some unwanted columns.

    I just use Excel to clean up the file:
    When you open the file in EXCEL, it will ask you how you want to format the columns.
    1) Select Delimited. Start import at row 1. Click NEXT.
    2) Set the delimiter as Space by checking the box. Uncheck the others. NEXT
    3) One at a time, highlight the Line, Address and Opcode columns and select Do Not Import (skip). Highlight the remaining columns and select Text as the import type. You should have 1 blank column at the left.
    4) Click FINISH. A sheet will open with the formatted source. Add a semicolon on the line that says Disassembly to comment it out.
    5) Save the file as .PRN -Formatted Text (Space Delimited).
    6) Rename the file as a .asm. (This one is .TXT to upload here)

    The example source recovery is for a 18F6722. The assembler code will be different for other PIC families. That's why you have to specify the PIC.

    Now you have a text file of the reconstructed program. It won't be easy to deal with because there is no symbolic information included but it should assemble.

    Have fun.
     
    Last edited: Dec 17, 2015
    Papabravo likes this.
  13. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    Recovering a source file from a .hex file can be done with a manual process, but there still is no automated application that can do it. Using Excel, or LibreOffice, to discard information from the disassembly listing is clever. Missing from the listing are any assembler directives that might be required to properly locate the program counter. These would need to be extracted from the .hex file or inferred from the memory dump page in MPLAB. Like John said this won't be particularly easy.

    One hint I can give you is to locate all of the return and return from interrupt (if any) instructions. The location following a return is usually the beginning of something which is the destination of a call.

    Good Luck
     
    Last edited: Dec 17, 2015
Loading...