Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating hex file using gcc

Tags:

c

gcc

hex

I have a small C function and I want to make a hex file for it.

Running

gcc -c in.c 

makes an object file But I need hex file for this standalone function. I need to put this on a separate location, so that I can simply JMP to this location from my main code. But I want this to be in hex format.

I cant do a -

gcc -c in.c -o in.hex 

This is not working.. Please help me out..

like image 337
Rgarg Avatar asked Oct 03 '13 07:10

Rgarg


People also ask

How do I save a text file as HEX?

Click "File," then "Save As" to save the text file to your hard drive. Choose the file extension HEX instead of the typical Notepad extension TXT. Doing so will allow any program that reads data from HEX files to read your hexadecimal code.

What is HEX file in microcontroller?

Intel hexadecimal object file format, Intel hex format or Intellec Hex is a file format that conveys binary information in ASCII text form. It is commonly used for programming microcontrollers, EPROMs, and other types of programmable logic devices and hardware emulators.

How do I run a HEX file?

HEX files are supported by several editors, including Heaventools FlexHex, Hex Workshop Hex Editor, and HexEdit. If you have a binary HEX file, it can only be opened with hex-editing programs. If you have a text-based HEX file, it can also be opened and edited with a text editor.


2 Answers

By using objcopy we can make hex file

gcc -c example.c

objcopy --change-address 0xE0000 -O ihex example.o example.hex

it will generate example.hex file

use Bless Hex Editor to see the .hex file clearly

like image 62
sujin Avatar answered Nov 02 '22 20:11

sujin


First you need to use the linker ld to create a raw binary binary file. Then use objcopy to create the hex file.

like image 45
Some programmer dude Avatar answered Nov 02 '22 18:11

Some programmer dude