Intel Hex records describe the hexadecimal object file format for 8-bit, 16-bit and 32-bit microprocessors. The hexadecimal object file is an ASCII representation of an absolute binary object file. There are six different types of records:
The ihex51 program generates records in the 8-bit format by default. When a section jumps over a 64k limit the program switches to 32-bit records automatically. 16-bit records can be forced with the -i16 option.
In the output file, the record format is:
: | length | offset | type | content | checksum |
Where:
: is the record header.
length is the record length which specifies the number of bytes of the content field. This value occupies one byte (two hexadecimal digits). The locator outputs records of 255 bytes (32 hexadecimal digits) or less; that is, length is never greater than FFH.
offset is the starting load offset specifying an absolute address in memory where the data is to be located when loaded by a tool. This field is two bytes long. This field is only used for Data Records. In other records this field is coded as four ASCII zero characters ('0000').
type is the record type. This value occupies one byte (two hexadecimal digits). The record types are:
Byte Type | Record type |
00 | Data |
01 | End of File |
02 | Extended segment address (20-bit) |
03 | Start segment address (20-bit) |
04 | Extended linear address (32-bit) |
05 | Start linear address (32-bit) |
content is the information contained in the record. This depends on the record type.
checksum is the record checksum. The locator computes the checksum by first adding the binary representation of the previous bytes (from length to content). The locator then computes the result of sum modulo 256 and subtracts the remainder from 256 (two's complement). Therefore, the sum of all bytes following the header is zero.
The Extended Linear Address Record specifies the two most significant bytes (bits 16-31) of the absolute address of the first data byte in a subsequent Data Record:
: | 02 | 0000 | 04 | upper_address | checksum |
The 32-bit absolute address of a byte in a Data Record is calculated as:
where:
address is the base address, where the two most significant bytes are the upper_address and the two least significant bytes are zero.
offset is the 16-bit offset from the Data Record.
index is the index of the data byte within the Data Record (0 for the first byte).
Example:
:0200000400FFFB | | | | |_ checksum | | | |_ upper_address | | |_ type | |_ offset |_ length
The Extended Segment Address Record specifies the two most significant bytes (bits 4-19) of the absolute address of the first data byte in a subsequent Data Record, where bits 0-3 are zero:
: | 02 | 0000 | 02 | upper_address | checksum |
The 20-bit absolute address of a byte in a Data Record is calculated as:
where:
address is the base address, where bits 4-19 are the upper_address and bits 0-3 are zero.
offset is the 16-bit offset from the Data Record.
index is the index of the data byte within the Data Record (0 for the first byte).
Example:
:0200000200FFFD | | | | |_ checksum | | | |_ upper_address | | |_ type | |_ offset |_ length
The Data Record specifies the actual program code and data.
: | length | offset | 00 | data | checksum |
The length byte specifies the number of data bytes. The locator has an option that controls the length of the output buffer for generating Data records. The default buffer length is 32 bytes.
The offset is the 16-bit starting load offset. Together with the address specified in the Extended Address Record it specifies an absolute address in memory where the data is to be located when loaded by a tool.
Example:
:0F00200000232222754E00754F04AF4FAE4E22C3 | | | | |_ checksum | | | |_ data | | |_ type | |_ offset |_ length
The Start Linear Address Record contains the 32-bit program execution start address.
Layout:
: | 04 | 0000 | 05 | address | checksum |
Example:
:0400000500FF0003F5 | | | | |_ checksum | | | |_ address | | |_ type | |_ offset |_ length
The Start Segment Address Record contains the 20-bit program execution start address.
Layout:
: | 04 | 0000 | 03 | address | checksum |
Example:
:0400000300FF0003F7 | | | | |_ checksum | | | |_ address | | |_ type | |_ offset |_ length
The hexadecimal file always ends with the following end-of-file record:
:00000001FF | | | |_ checksum | | |_ type | |_ offset |_ length