[Hex format file operations] 1. intel hex format file description

Source: Internet
Author: User

For detailed format descriptions, see:

1. Intel Hexadecimal Object File Format Specification 1988 (PDF), Revision A, January 6, 1988

2. http://en.wikipedia.org/wiki/Intel_hex

______________________________________________________________________________________________

What is Intel HEX format?

An Intel HEX file is an ASCII text file that records text lines. In an Intel HEX file, each row is a hex record, a machine code or data constant consisting of hexadecimal numbers,
Intel hex files are often used to transmit programs or data to Rom and EPROM. Most programmers and simulators use intel hex files.

Record format

An Intel HEX file can contain any number of hexadecimal records. Each record has five fields. The following is a record format.

: Llaaaatt [DD...] CC

Each group of letters is an independent domain. Each letter is a hexadecimal number. Each domain consists of at least two hexadecimal numbers. The following is a byte description.

: Colon is the start of each intel hex record

Ll is the length field of this record, which indicates the number of bytes of data (dd.

Aaaa is the address field, which indicates the starting address of the data.
<If it is a data record, this indicates the offset address of the data in the record to be burned in the EPROM,
For those that do not support extended segment addresses and extended linear addresses, such as 89C51, this is the starting address of this record>

TT indicates the type of the hex record. It may be the following types:
00 ---- data record
01 ---- end of File
02 ---- extended segment address record
04 ---- Extended Linear address records

Dd is a data field that represents one byte of data. A record may contain multiple data bytes. For details about the number of bytes, see the description of LL domain.

CC is the effect and domain, indicating the effect and calculation of the record. The calculation method is to associate all the letter pairs starting with the colon

<Do not include the hexadecimal number indicated by this verification word and colon>
<A pair of letters indicates a hexadecimal number. Such a hexadecimal number is a byte.>

All add up and then divide the remainder obtained by MoD 256. The final complement code for finding the remainder is the effective byte cc.
<Example:
: 0300000002005E9D
Cc = 0x01 + NOT (0x03 + 0x00 + 0x00 + 0x00 + 0x02 + 0x00 + 0x5E) % 0x100) = 0x01 + 0x9C = 0x9D

C language description:
UCHAR cc;
Cc = (UCHAR )~ (0x03 + 0x00 + 0x00 + 0x00 + 0x02 + 0x00 + 0x5E );
Cc ++;
>
Data Records

An Intel HEX file consists of several data records. A Data Record ends with a carriage return and a line feed. <enter 0x0 d for behavior 0x0 A>

For example, the following data record
: 10246200464C5549442050524F46494C4500464C33

10 is the number of bytes of data recorded in this row.
2462 is the starting address of the data in the memory <the eprom address to be written>
00 is the record Type 00 (a data record)
464C to 464C is Data
33 is the validation and

Extended Linear Address Record (HEX386)
Extended Linear address records are also known as 32-bit address records and hex386 records, which contain 16-31 (16-31) high-Bit Data addresses. Such Extended Linear records always have two bytes of data, as shown below:

: 02000004 fffffc
02 is the number of data bytes recorded
0000 is the address field, which is always 0000 in the extended address record.
04 is record type 04 (Extended Address Record)
FFFF is a 16-bit high address.
The FC is the record verification sum. The calculation method is as follows:
01 H + not (02 H + 00 H + 00 H + 04 H + FFH)

When an Extended Linear address record is read, the data area of the Extended Linear address record is saved.
And applied to the records read from Intel hex files. This Extended Linear record is always valid,
Until you read The Next Extended Linear record.

Absolute Memory Address = address in the data record + expanded linear address after shift

The following is an example of this process.

Get address 2462 from the address field of the data record
Obtain the address FFFF from the address field of the Extended Linear address record.
Absolute Memory Address ffff2462

Extended segment address record (hex86)

The extended segment address record is also known as the hex86 record, which contains 4-19 data address segments,
This extended segment address record always has two bytes of data, as shown below:

: 020000021200ea
02 is the number of data bytes in the record
0000 is the address field. In the extended segment address record, this field is always 0000
02 is record type 02 (Extended segment address ID)
1200 is the address of the segment
EA is a validation and
The calculation is as follows:
01 H + not (02 H + 00 H + 00 H + 02 H + 12 h + 00 H ).

When the extended segment address record is read, the extended segment address will be stored and applied to the record that will be read from the Intel HEX file later. This segment address remains valid until it reads the next extended segment address record.

Absolute Memory Address = address in the data record + extended segment address after shift

The address field in the extended segment address record after the address field in the data record is moved

The following is an example of this process.

Obtain Address 2 4 6 2 from the address field of the data record
Obtain Address 1 2 0 0 from the address field of the extended segment address record
Absolute Memory Address 0 0 0 1 4 4 6 2

End of file (EOF)
An Intel HEX file must have a file end record. The type field of this record must be 01,
An EOF record always looks like this:
: 00000001FF
00 indicates the number of data bytes in the record.
0000 this address is meaningless for the EOF record
01 The record type is 01 (End record mark)
FF is the verification and calculation as follows
01 h + NOT (00 h + 00 h + 00 h + 01 h ).
======================================

Summary

Shape
: BBAAAATTHHHH... HHHHCC

BB: Byte
AAAA: the starting address of the data record. The highest position is in the back
Because this format only supports 8 bits, the address is multiplied
Therefore, in order to obtain the actual PIC address, we need to divide the address by 2
TT: Type
00 data records
01 end of record
04 extended Address Record (indicating the 32-bit address prefix, of course, this can only be in INHX32)
HHHH: a data record of a Word, with a high Byte in front and a low Byte in the back
After TT, there are a total of BB/2 Characters of data
CC: the CheckSum of a Byte

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.