I am studying assembly language programming.I came across steps to a program for a microcontroller.
In the last step why is the .obj file is converted to .hex file. The process says that file is converted to .hex and burned to ROM.As per my understanding the .obj file is already a machine language code and can be run.
If this question makes sense please explain why is there a need of OH converter in the last step?
-
1Some EEPROM programmers want `.hex` files as input, instead of raw binary. It's apparently not just a hexdump, though; it has addresses for each line so the programming software knows what to put where. e.g. [tag:srecord]. Instead of understanding some binary executable file format. (At least that's my understanding; I've never used any of that, just normal toolchains to make binary executables that run under OSes.) – Peter Cordes Aug 28 '20 at 07:30
-
1*per my understanding the .obj file is already a machine language code* YES. *and can be run.* NO. A not-yet-linked `.obj` only has metadata with symbol names, not actual offsets to symbol addresses. And potentially multiple sections that haven't been laid out in memory. Also, this seems to be a separate question from why converting to hex after linking. – Peter Cordes Aug 28 '20 at 07:31
-
Till linking it is clear. Since code will anyway be going to store in Rom in 0 and 1. Why is hex converter needed – PARUL Aug 28 '20 at 08:56
-
1@PeterCordes Intel hex and Motorola s-record are very similar but competing ASCII formats for expressing everything inside the raw binary. Microcontrollers tend to indirectly belong to either of these old camps. Intel derivatives such as 8051 families and spawn-offs use Intel Hex (Infineon, TI, Microchip, Phillips/some NXP etc). Motorola s-record is for 6800 derivatives and spawn-offs (Motorola/Freescale/some NXP, Renesas/Hitachi, Atmel, ST etc). ARM Cortex M no matter manufacturer tend to sit somewhere in between, sometimes even supporting all formats. – Lundin Aug 28 '20 at 09:28
-
1@Lundin: I wasn't sure if the OP meant Intel Hex specifically, or just any file format that used an ASCII hexadecimal representation. On 2nd look, yeah they mention `.hex`, so adding [tag:srecord] was apparently a mistake, and was always just a sort of wild guess / semi-related tag when I first chose to add it. Is [tag:hex-file] supposed to be about Intel Hex format, rather than hexdumps in general? I saw it while searching but the tag excerpt didn't give any hint it was about memory-image / ROM programming `.hex` format. I thought it was for plain hexdump / hex-undump stuff; edited to fix – Peter Cordes Aug 28 '20 at 09:40
-
@PeterCordes Yeah the tag is supposedly for hex files though the tag wiki is poor. – Lundin Aug 28 '20 at 12:50
1 Answers
"obj" could be anything, there's no standard. It may be machine code, it may be some abstract "object code" format, it may or may not contain debugging information (such as variable/function names). Typically it is not the final binary but a format that the linker understands.
Even if you write in assembler, you have to download that code into memory somehow, either through an in-circuit debugger or through a dedicated circuit programmer. Then you need a file format that your tool can handle.
"abs" is typically machine code but with debugging information included, used for downloading and troubleshooting a program through a debugger.
"hex" is standardized "Intel hex" format, which is raw machine code with no debugging info, expressed in an ASCII format. It is commonly used by in-circuit programmers and a common format to use for the final product binary in production. (Other such common formats are .bin and .s19)

- 195,001
- 40
- 254
- 396