Monday, January 21, 2013

Understanding Intel Hex file

Intel hex file is a file which contains binary data values to program micro-controllers, EEPROMs,  and other chips. Compiler converts source code into machine code and outputs it into hex file. This hex file then burned into chip using burner for make chip functional.

Typical look of hex file is...


Now each line has six different meaningful parts and these parts are...

1) Starting Code
2) Byte Count
3) Memory Address
4) Record Type
5) Data
6) Checksum


1) Start Code: It is a single character an ASCII code of colon(":"). Every line of hex file is starts with colon. It indicates the new line in hex file.

2) Byte Count: It consist of two hex character and it represents the length of data bytes in the record.

3) Memory Address: It consist of 4-digit memory location that represent the starting address of subsequent data in the record. Data starts storing from this memory location and its increments after storing of each data byte.

4) Record type: It consists of two hex digits. There are six types of records. This field has only five possible values which are from 00 to 05.

=> 00 = Data record; which contains data and 16-bit address.

=> 01 = End of file records; every hex file must be end with end of file record type for that record type field must contains "01". End of file records always has following format.


=> 02 = Extended segment address records; it is also known as HEX86. Extended segment record must have two data bytes. Absolute 32-bit address is generated using addition of extended segment address's data field and data record's address field.

=> 04 = Start segment address record; this is for 80x86 processors. it specifies the initial contents of code segment and instruction pointer. Here 1st two values (bytes) of data field are for code segment and other two are for instruction pointer.

=> 05 = Start linear address records; This is for 80386 and higher CPU. Contents of data field that is of 32-bit are loaded into the EIP register.

5) Data Field: This field contents data byte and address as well. Content of record field differentiate whether it is data or an address.

6) Checksum: This is two hex digits appears at the end of each line. For calculating this number 1st add every hex number of line not include ":" and checksum field it self then perform 2's compliment of least significant byte.

Please share this with your friend...

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.