The Intel HEX file is an ASCII text file that encodes and represents a binary file. Each line in an Intel HEX file contains one HEX record.
These HEX records are made up of hexadecimal numbers that represent machine language code or binary data. Intel HEX files are often used to transfer the program and data that would be stored in a ROM or EPROM. Most EPROM programmers or emulators can use the Intel HEX format.
Intel Record Format
An Intel HEX file is composed of any number of HEX records. Each record is made up of five fields that are arranged in the following format:
:LLaaaaTT[dd...]cc
Each group of letters corresponds to a different field, and each letter represents a single hexadecimal digit. Each field is composed of at least two hexadecimal digits-which make up a byte-as described below:
: is the colon that starts every Intel HEX record.
LL is the record-length field that represents the number of data bytes (dd) in the record.
aaaa is the address field that represents the starting address for subsequent data in the record.
TT is the feild that represents the HEX record type, which may be one of the following:
00 - data record 01 - end-of-file record 02 - extended segment address record 04 - extended linear address record
dd is a data field that represents one byte of data. A record may have multiple data bytes. The number of data bytes in the record must match the number specified by the ll field.
cc is the checksum field that represents the checksum of the record. The checksum is calculated by summing the values of all hexadecimal digit pairs in the record modulo 256 and taking the two's complement.
Data Records
The Intel HEX file is made up of any number of data records that are terminated with a carriage return and a linefeed. Data records appear as follows:
:10246200464C5549442050524F46494C4500464C33
This record is decoded as follows:
:10246200464C5549442050524F46494C4500464C33 :|||||||||| CC->Checksum :||||||||dd->Data :||||||TT->Record Type :||aaaa->Address :LL->Record Length
where:
10 is the number of data bytes in the record.
2462 is the address where the data are to be located in memory.
00 is the record type 00 (a data record).
464C...464C is the data.
33 is the checksum of the record.
Extended Linear Address Records (HEX386)
Extended linear address records are also known as 32-bit address records and HEX386 records. These records contain the upper 16 bits (bits 16-31) of the data address. The extended linear address record always has two data bytes and appears as follows:
:02000004FFFFFC
where:
02 is the number of data bytes in the record.
0000 is the address field. For the extended linear address record, this field is always 0000.
04 is the record type 04 (an extended linear address record).
FFFF is the upper 16 bits of the address.
FC is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 04h + FFh + FFh).
When an extended linear address record is read, the extended linear address stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The linear address remains effective until changed by another extended address record.
The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted address data from the extended linear address record. The following example illustrates this process..
Address from the data record's address field 2462 Extended linear address record data field FFFF -------- Absolute-memory address FFFF2462
Extended Segment Address Records (HEX86)
Extended segment address records-also known as HEX86 records-contain bits 4-19 of the data address segment. The extended segment address record always has two data bytes and appears as follows:
:020000021200EA
02 is the number of data bytes in the record.
0000 is the address field. For the extended segment address record, this field is always 0000.
02 is the record type 02 (an extended segment address record).
1200 is the segment of the address.
EA is the checksum of the record and is calculated as 01h + NOT(02h + 00h + 00h + 02h + 12h + 00h).
When an extended segment address record is read, the extended segment address stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The segment address remains effective until changed by another extended address record.
The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted-address data from the extended segment address record. The following example illustrates this process.
Address from the data record's address field 2462 Extended segment address record data field 1200 -------- Absolute memory address 00014462
End-of-File (EOF) Records An Intel HEX file must end with an end-of-file (EOF) record. This record must have the value 01 in the record type field. An EOF record always appears as follows:
:00000001FF
00 is the number of data bytes in the record.
0000 is the address where the data are to be located in memory. The address in end-of-file records is meaningless and is ignored. An address of 0000h is typical.
01 is the record type 01 (an end-of-file record).
FF is the checksum of the record and is calculated as 01h + NOT(00h + 00h + 00h + 01h).
Example Intel HEX File
Following is an example of a complete Intel HEX file:
Intel HEX is a file format for conveying binary information for applications like programming microcontrollers, EPROMs, and other kinds of chips. It is one of the oldest file formats available for this purpose.
The format is a text file, with each line containing hexadecimal values encoding a sequence of data and their starting offset or absolute address.
There are three types of Intel HEX: 8-bit, 16-bit, and 32-bit. They are distinguished by their byte order.
Each line of Intel HEX file consists of six parts:
1. Start code, one character, an ASCII colon ':'.
2. Byte count, two hex digits, a number of bytes (hex digit pairs) in the data field. 16 (10) or 32 (20) bytes of data are the usual compromise values between line length and address overhead.
3. Address, four hex digits, a 16-bit address of the beginning of the memory position for the data. Limited to 64 kilobytes, the limit is worked around by specifying higher bits via additional record types.
4. Record type, two hex digits, 00 to 05, defining the type of the data field.
5. Data, a sequence of n bytes of the data themselves. 2n hex digits.
6. Checksum, two hex digits - the least significant byte of the two's complement sum of the values of all fields except fields 1 and 6. It is calculated by adding together the hex-encoded bytes (hex digit pairs), taking only the LSB, and inverting the bytes (XORing 0xFF) or subtracting the byte from 0x100.
There are six record types:
00, data record, contains data and 16-bit address. The format described above.
01, End Of File record, a file termination record. No data. Has to be the last line of the file, only one per file permitted. Usually ':00000001FF'.
02, Extended Segment Address Record, segment-base address. Used when 16 bits is not enough, identical to 80x86 real mode addressing. The address specified by the 02 record is multiplied by 16 (shifted 4 bytes left) and added to the subsequent 00 record addresses. This allows addressing of up to a megabyte of address space. The address field of this record has to be 0000, the byte count is 02 (the segment is 16-bit). The least significant hex digit of the segment address is always 0.
03, Start Segment Address Record. For 80x86 processors, it specifies the initial content of the CS:IP registers. The address field is 0000, the byte count is 04, the first two bytes are the CS value, the latter two are the IP value.
04, Extended Linear Address Record, allowing for fully 32 bit addressing. The address field is 0000, the byte count is 02. The two data bytes represent the upper 16 bits of the 32 bit address, when combined with the address of the 00 type record.
05, Start Linear Address Record. The address field is 0000, the byte count is
04. The 4 data bytes represent the 32-bit value loaded into the EIP register of the 80386 and higher CPU. To confuse the matter, there are various format subtypes:
I8HEX or INTEL 8, 8-bit format.
I16HEX or INTEL 16, 16-bit format. Allows usage of 02 records. The data field endianness may be byte-swapped.
I32HEX or INTEL 32, 32-bit format. Allows usage of 03, 04, and 05 records. The data field endianness may be byte-swapped.
Beware of byte-swapped data. Some programmers tend to misinterpret the byte order in case of I16HEX and I32HEX.
AVR_Admin- 04-24-2006
Here is the Intel Hex PDF...
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.