Intel HEX

1.0 Introduction

The Intel 32-bit Hexadecimal Object file record format has a 9-character, 4 field, prefix that defines the start of record, byte count, load address and record type. The record format also has a 2-character suffix containing a checksum.

Color legend

As a visual aid, the fields of Intel HEX records are colored throughout this article as follows:

.mw-parser-output .legend{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .legend-color{display:inline-block;min-width:1.25em;height:1.25em;line-height:1.25;margin:1px 0;text-align:center;border:1px solid black;background-color:transparent;color:black}.mw-parser-output .legend-text{}  Start code   Byte count   Address   Record type   Data   Checksum

Checksum calculation

A record’s checksum byte is the two’s complement of the least significant byte (LSB) of the sum of all decoded byte values in the record preceding the checksum. It is computed by summing the decoded byte values and extracting the LSB of the sum (i.e., the data checksum), and then calculating the two’s complement of the LSB (e.g., by inverting its bits and adding one).

For example, in the case of the record :0300300002337A1E, the sum of the decoded byte values is 03 + 00 + 30 + 00 + 02 + 33 + 7A = E2, which has LSB value E2. The two’s complement of E2 is 1E, which is the checksum byte appearing at the end of the record.

Hex code Record type Description Example
00 Data The byte count specifies number of data bytes in the record. The example has 0B (eleven) data bytes. The 16-bit starting address for the data (in the example at addresses beginning at 0010) and the data (61, 64, 64, 72, 65, 73, 73, 20, 67, 61, 70). 8 (0x08),[9] 16 (0x10)[9] and 32 (0x20) are commonly used byte counts. Not all software copes with counts larger than 16.[2] :0B0010006164647265737320676170A7
01 End Of File Must occur exactly once per file in the last record of the file. The byte count is 00, the address field is typically 0000 and the data field is omitted. :00000001FF
02 Extended Segment Address The byte count is always 02, the address field (typically 0000) is ignored and the data field contains a 16-bit segment base address. This is multiplied by 16 and added to each subsequent data record address to form the starting address for the data. This allows addressing up to one mebibyte (1048576 bytes) of address space. :020000021200EA
03 Start Segment Address For 80×86 processors, specifies the starting execution address. The byte count is always 04, the address field is 0000 and the first two data bytes are the CS value, the latter two are the IP value. The execution should start at this address. :0400000300003800C1
04 Extended Linear Address Allows for 32 bit addressing (up to 4 GiB). The byte count is always 02 and the address field is ignored (typically 0000). The two data bytes (big endian) specify the upper 16 bits of the 32 bit absolute address for all subsequent type 00 records; these upper address bits apply until the next 04 record. The absolute address for a type 00 record is formed by combining the upper 16 address bits of the most recent 04 record with the low 16 address bits of the 00 record. If a type 00 record is not preceded by any type 04 records then its upper 16 address bits default to 0000. :020000040800F2
05 Start Linear Address The byte count is always 04, the address field is 0000. The four data bytes represent a 32-bit address value (big-endian). In the case of CPUs that support it, this 32-bit address is the address at which execution should start. :04000005000000CD2A

2.0 Record Types

The Intel 32-bit Hexadecimal Object file record format contains six record types

00 Data Record
01 End Record
02 Extended Segment Address Record
03 Start Segment Address Record
04 Extended Linear Address Record
05 Start Linear Address Record

2.1 Data Record

Record type 00, the data record, is the record which contains the data of the file. The data record begins with the colon start character (“:”) followed by the byte count, the address of the first byte and the record type (“00”). Following the record type are the data bytes. The checksum follows the data bytes and is the 2’s compliment of the preceding bytes in the record, excluding the start character. The following are examples of data records (spaces are included for clarity only and should not be found in a real object file).

:10 0000 00 FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0 FF
:05 0010 00 0102030405 AA

2.2 End Record

Record type 01, the end record, signals the end of the data file. The end record starts with the colon start character (“:”) followed by the byte count (“00”), the address (“0000”), the record type (“01”) and the checksum (“FF”).

:00 0000 01 FF

2.3 Extended Segment Address Record

Record type 02, the extended segment address record, defines bits 4 through 19 of the segment base address. It can appear anywhere within the object file and it affects the absolute memory address of all subsequent data records in the file until it is changed. The extended segment address record starts with the colon start character (“:”) followed by the byte count (“02”), the address (“0000”), the record type (“02”), the 4 character ASCII representation of the hexadecimal number represented by bits 4 through 19 of the segment base address and the 2 character checksum.

:02 0000 02 1000 55

2.4 Start Segment Address Record

Record type 03, the start segment address record, defines bits 4 through 19 of the execution start segment base address for the object file. This record is currently ignored.

:02 0000 03 0000 55

2.5 Extended Linear Address Record

Record type 04, the extended linear address record, defines bits 16 through 31 of the destination address. It can appear anywhere in within the object file and it affects the absolute memory address of all subsequent data records in the file until it is changed. The extended linear address record starts with the colon start character (“:”) followed by the byte count (“02”), the address (“0000”), the record type (“04”),the 4 character ASCII representation of the hexadecimal number represented by bits 16 through 31 of the destination address and the 2 character checksum.

:02 0000 04 FFFF 55

2.6 Start Linear Address Record

Record type 05, the start linear address record, defines bits 16 through 31 of the execution start address for the object file. This record is currently ignored.

:02 0000 05 0000 55

3.0 Example

The following is an example of an Intel Hexadecimal Object file record. It contains the following records: extended linear address,extended segment address, data and end.

:020000040108EA

:020000040108EA

:0200000212FFBD

:0200000212FFBD

:0401000090FFAA5502

:0401000090FFAA5502

:00000001FF

:00000001FF

1. Determine the extended linear address offset for the data record (0108 in this example).

:02 0000 04 0108 EA

2. Determine the extended segment address for the data record (12FF in this example).

:02 0000 02 12FF BD

3. Determine the address offset for the data in the data record (0100 in this example).

:04 0100 00 90FFAA55 02

4. Calculate the absolute address for the first byte of the data record.

0108 0000 linear address offset shifted left 16 bits
+ 0001 2FF0 segment address offset shifted left 4 bits
+ 0000 0100 address offset from data record
= 0109 30F0 32 bit address for first data byte

5. Which gives us the following

010930F0 90
010930F1 FF
010930F2 AA
010930F3 55

By navalkishorjha