MPLAB And Hex Listing To Hex Executable

Thread Starter

waynerr

Joined Jun 21, 2009
5
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​
 

Papabravo

Joined Feb 24, 2006
21,157
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.
 

joeyd999

Joined Jun 6, 2011
5,234
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.
 

Papabravo

Joined Feb 24, 2006
21,157
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.
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.
 

joeyd999

Joined Jun 6, 2011
5,234
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.
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.
 

Papabravo

Joined Feb 24, 2006
21,157
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:

ErnieM

Joined Apr 24, 2011
8,377
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.
 

Papabravo

Joined Feb 24, 2006
21,157
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.
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".
 

Thread Starter

waynerr

Joined Jun 21, 2009
5
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".
 

JohnInTX

Joined Jun 26, 2012
4,787
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.
 

Attachments

Last edited:

Papabravo

Joined Feb 24, 2006
21,157
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:
Top