Английская Википедия:Intel HEX

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Distinguish Шаблон:Redirect Шаблон:Use dmy dates Шаблон:Use list-defined references Шаблон:Infobox file format

Intel hexadecimal object file format, Intel hex format or Intellec Hex is a file format that conveys binary information in ASCII text form,[1] making it possible to store on non-binary media such as paper tape, punch cards, etc., to display on text terminals or be printed on line-oriented printers.[2] The format is commonly used for programming microcontrollers, EPROMs, and other types of programmable logic devices and hardware emulators. In a typical application, a compiler or assembler converts a program's source code (such as in C or assembly language) to machine code and outputs it into a object or executable file in hexadecimal (or binary) format. In some applications, the Intel hex format is also used as a container format holding packets of stream data.[3] Common file extensions used for the resulting files are .HEX[4] or .H86.[5][6] The HEX file is then read by a programmer to write the machine code into a PROM or is transferred to the target system for loading and execution.[2][7] There are various tools to convert files between hexadecimal and binary format (i.e. HEX2BIN), and vice versa (i.e. OBJHEX, OH, OHX, BIN2HEX).

History

The Intel hex format was originally designed for Intel's Intellec Microcomputer Development Systems[8]Шаблон:Rp (MDS) in 1973 in order to load and execute programs from paper tape. It was also used to specify memory contents to Intel for ROM production,[9] which previously had to be encoded in the much less efficient BNPF (Begin-Negative-Positive-Finish) format.[8]Шаблон:Rp In 1973, Intel's "software group" consisted only of Bill Byerly and Kenneth Burgett, and Gary Kildall as an external consultant doing business as Microcomputer Applications Associates (MAA) and founding Digital Research in 1974.[10][11][12][13] Beginning in 1975, the format was utilized by Intellec Series II ISIS-II systems supporting diskette drives, with files using the file extension HEX.[14] Many PROM and EPROM programming devices accept this format.

Format

Intel HEX consists of lines of ASCII text that are separated by line feed or carriage return characters or both. Each text line contains uppercase hexadecimal characters that encode multiple binary numbers. The binary numbers may represent data, memory addresses, or other values, depending on their position in the line and the type and length of the line. Each text line is called a record.

Record structure

A record (line of text) consists of six fields (parts) that appear in order from left to right:[2]

  1. Start code, one character, an ASCII colon 'Шаблон:Background color'. All characters preceding this symbol in a record should be ignored.[9][5][15][16][17][18] In fact, very early versions of the specification even asked for a minimum of 25 NUL characters to precede the first record and follow the last one, owing to the format's origins as a paper tape format which required some tape leadin and leadout for handling.[9][19][16][17] However, as this was a little known part of the specification, not all software written copes with this correctly. It allows to store other related information in the same file (and even the same line),[9][18] a facility used by various software development utilities to store symbol tables or additional comments,[20][9][16][21][13][22] and third-party extensions using other characters as start code like the digits 'Шаблон:Background color'..'Шаблон:Background color' by Intel[23] and Keil,[21] 'Шаблон:Background color' by Mostek,[24][25] or 'Шаблон:Background color', 'Шаблон:Background color', 'Шаблон:Background color', 'Шаблон:Background color', 'Шаблон:Background color' and 'Шаблон:Background color' by TDL.[25][26] By convention, 'Шаблон:Background color' is often used for comments.[27][28] Neither of these extensions may contain any ':' characters as part of the payload.
  2. Byte count, two hex digits (one hex digit pair), indicating the number of bytes (hex digit pairs) in the data field. The maximum byte count is 255 (0xFF). 8 (0x08),[13] 16 (0x10)[13] and 32 (0x20) are commonly used byte counts. Not all software copes with counts larger than 16.[29]
  3. Address, four hex digits, representing the 16-bit beginning memory address offset of the data. The physical address of the data is computed by adding this offset to a previously established base address, thus allowing memory addressing beyond the 64 kilobyte limit of 16-bit addresses. The base address, which defaults to zero, can be changed by various types of records. Base addresses and address offsets are always expressed as big endian values.
  4. Record type (see record types below), two hex digits, Шаблон:Intel HEX to Шаблон:Intel HEX, defining the meaning of the data field.
  5. Data, a sequence of n bytes of data, represented by 2n hex digits. Some records omit this field (n equals zero). The meaning and interpretation of data bytes depends on the application. (4-bit data will either have to be stored in the lower or upper half of the bytes, that is, one byte holds only one addressable data item.[9])
  6. Checksum, two hex digits, a computed value that can be used to verify the record has no errors.

Color legend

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

Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline

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 Шаблон:Intel HEX, the sum of the decoded byte values is Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX = E2, which has LSB value E2. The two's complement of E2 is Шаблон:Intel HEX, which is the checksum byte appearing at the end of the record.

The validity of a record can be checked by computing its checksum and verifying that the computed checksum equals the checksum appearing in the record; an error is indicated if the checksums differ. Since the record's checksum byte is the two's complement — and therefore the additive inverse — of the data checksum, this process can be reduced to summing all decoded byte values, including the record's checksum, and verifying that the LSB of the sum is zero. When applied to the preceding example, this method produces the following result: Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX + Шаблон:Intel HEX = 100, which has LSB value 00.

Text line terminators

Intel HEX records are usually separated by one or more ASCII line termination characters so that each record appears alone on a text line. This enhances readability by visually delimiting the records and it also provides padding between records that can be used to improve machine parsing efficiency. However, the line termination characters are optional, as the 'Шаблон:Background color' is used to detect the start of a record.[9][5][19][15][16][17][18]

Programs that create HEX records typically use line termination characters that conform to the conventions of their operating systems. For example, Linux programs use a single LF (line feed, hex value 0A) character to terminate lines, whereas Windows programs use a CR (carriage return, hex value 0D) followed by a LF.

Record types

Intel HEX has six standard record types:[2]

Hex code Record type Description Example
Шаблон:Intel HEX Data The byte count specifies number of data bytes in the record. The example has Шаблон:Intel HEX (eleven) data bytes. The 16-bit starting address for the data (in the example at addresses beginning at Шаблон:Intel HEX) and the data (Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX, Шаблон:Intel HEX). Шаблон:Intel HEX
Шаблон:Intel HEX End Of File Must occur exactly once per file in the last record of the file. The byte count is Шаблон:Intel HEX, the address field is typically Шаблон:Intel HEX and the data field is omitted. Шаблон:Intel HEX
Шаблон:Intel HEX Extended Segment Address The byte count is always Шаблон:Intel HEX, the address field (typically Шаблон:Intel HEX) 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. Шаблон:Intel HEX
Шаблон:Intel HEX Start Segment Address For 80x86 processors, specifies the starting execution address. The byte count is always Шаблон:Intel HEX, the address field is Шаблон:Intel HEX and the first two data bytes are the CS value, the latter two are the IP value. The execution should start at this address. Шаблон:Intel HEX
Шаблон:Intel HEX Extended Linear Address Allows for 32 bit addressing (up to 4 GiB). The byte count is always Шаблон:Intel HEX and the address field is ignored (typically Шаблон:Intel HEX). The two data bytes (big endian) specify the upper 16 bits of the 32 bit absolute address for all subsequent type Шаблон:Intel HEX records; these upper address bits apply until the next Шаблон:Intel HEX record. The absolute address for a type Шаблон:Intel HEX record is formed by combining the upper 16 address bits of the most recent Шаблон:Intel HEX record with the low 16 address bits of the Шаблон:Intel HEX record. If a type Шаблон:Intel HEX record is not preceded by any type Шаблон:Intel HEX records then its upper 16 address bits default to 0000. Шаблон:Intel HEX
Шаблон:Intel HEX Start Linear Address The byte count is always Шаблон:Intel HEX, the address field is Шаблон:Intel HEX. 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. Шаблон:Intel HEX

Other record types have been used for variants, including Шаблон:Intel HEX ('blinky' messages / transmission protocol container) by Wayne and Layne,[30] Шаблон:Intel HEX (block start), Шаблон:Intel HEX (block end), Шаблон:Intel HEX (padded data), Шаблон:Intel HEX (custom data) and Шаблон:Intel HEX (other data) by the BBC/Micro:bit Educational Foundation,[31] and Шаблон:Intel HEX (data in code segment), Шаблон:Intel HEX (data in data segment), Шаблон:Intel HEX (data in stack segment), Шаблон:Intel HEX (data in extra segment), Шаблон:Intel HEX (paragraph address for absolute code segment), Шаблон:Intel HEX (paragraph address for absolute data segment), Шаблон:Intel HEX (paragraph address for absolute stack segment) and Шаблон:Intel HEX (paragraph address for absolute extra segment) by Digital Research.[6][15]

Шаблон:AnchorNamed formats

The original 4-bit/8-bit Intellec Hex Paper Tape Format and Intellec Hex Computer Punched Card Format in 1973/1974 supported only one record type Шаблон:Intel HEX.[32][33][20] This was expanded around 1975Шаблон:When to also support record type Шаблон:Intel HEX.[9] Sometimes called symbolic hexadecimal format,[34] it could include an optional header containing a symbol table for symbolic debugging,[20][23][21][13] all characters in a record preceding the colon are ignored.[9][5]

Around 1978Шаблон:When, Intel introduced the new record types Шаблон:Intel HEX and Шаблон:Intel HEX (to add support for the segmented address space of the then-new 8086/8088 processors) in their Extended Intellec Hex Format.Шаблон:When

Special names are sometimes used to denote the formats of HEX files that employ specific subsets of record types. For example:

File example

This example shows a file that has four data records followed by an end-of-file record:

Шаблон:Intel HEX
Шаблон:Intel HEX
Шаблон:Intel HEX
Шаблон:Intel HEX
Шаблон:Intel HEX

Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline Шаблон:Legend inline

Шаблон:AnchorVariants

Besides Intel's own extension, several third-parties have also defined variants and extensions of the Intel hex format, including Digital Research (as in the so-called "Digital Research hex format"[6][15]), Zilog, Mostek,[24][25] TDL,[25][26] Texas Instruments, Microchip,[35][36] c't, Wayne and Layne,[30] and BBC/Micro:bit Educational Foundation (with its "Universal Hex Format"[31]). These can have information on program entry points and register contents, a swapped byte order in the data fields, fill values for unused areas, fuse bits, and other differences.

The Digital Research hex format for 8086 processors supports segment information by adding record types to distinguish between code, data, stack, and extra segments.[5][6][15]

Most assemblers for CP/M-80 (and also XASM09 for the Motorola 6809) don't use record type 01h to indicate the end of a file, but use a zero-length data type 00h entry instead.[37][4] This eases the concatenation of multiple hex files.[38][39][4]

Texas Instruments defines a variant where addresses are based on the bit-width of a processor's registers, not bytes.

Шаблон:AnchorMicrochip defines variants INTHX8S[40] (INHX8L,[4] INHX8H[4]), INHX8M,[40][4][41] INHX16[40] (INHX16M[4]) and INHX32[42] for their PIC microcontrollers.

Alfred Arnold's cross-macro-assembler AS,[4] Werner Hennig-Roleff's 8051-emulator SIM51,[21] and Matthias R. Paul's cross-converter BINTEL[43] are also known to define extensions to the Intel hex format.

See also

References

Шаблон:Over-quotation Шаблон:Reflist

Further reading

External links

  • binex - a converter between Intel HEX and binary for Windows.
  • SRecord, a converter between Intel HEX and binary for Linux (usage), C++ source code.
  • kk_ihex, open source C library for reading and writing Intel HEX
  • libgis, open source C library that converts Intel HEX, Motorola S-Record, Atmel Generic files.
  • bincopy is a Python package for manipulating Intel HEX files.
  • SwiftIntelHex - a Swift package to parse Intel HEX files for iOS and macOS.

  1. 1,0 1,1 Ошибка цитирования Неверный тег <ref>; для сносок Intel_1980_FU-UG не указан текст
  2. 2,0 2,1 2,2 2,3 Ошибка цитирования Неверный тег <ref>; для сносок Intel_1988_Spec не указан текст
  3. Ошибка цитирования Неверный тег <ref>; для сносок Analog_2021 не указан текст
  4. 4,0 4,1 4,2 4,3 4,4 4,5 4,6 4,7 Ошибка цитирования Неверный тег <ref>; для сносок Arnold_2020_AS не указан текст
  5. 5,0 5,1 5,2 5,3 5,4 Ошибка цитирования Неверный тег <ref>; для сносок DRI_1981_CPM86-SG не указан текст
  6. 6,0 6,1 6,2 6,3 Ошибка цитирования Неверный тег <ref>; для сносок DRI_1983_CPM86-PG не указан текст
  7. Ошибка цитирования Неверный тег <ref>; для сносок ARM_hex не указан текст
  8. 8,0 8,1 Ошибка цитирования Неверный тег <ref>; для сносок Crosby_1994 не указан текст
  9. 9,0 9,1 9,2 9,3 9,4 9,5 9,6 9,7 9,8 Ошибка цитирования Неверный тег <ref>; для сносок Intel_1977 не указан текст
  10. Ошибка цитирования Неверный тег <ref>; для сносок Kildall_1980_CPM не указан текст
  11. Ошибка цитирования Неверный тег <ref>; для сносок Kildall_1993 не указан текст
  12. Ошибка цитирования Неверный тег <ref>; для сносок Burgett_2017 не указан текст
  13. 13,0 13,1 13,2 13,3 13,4 Ошибка цитирования Неверный тег <ref>; для сносок Roche_2020 не указан текст
  14. Ошибка цитирования Неверный тег <ref>; для сносок Feichtinger_1987 не указан текст
  15. 15,0 15,1 15,2 15,3 15,4 Ошибка цитирования Неверный тег <ref>; для сносок DRI_1984_CCPM-PRG не указан текст
  16. 16,0 16,1 16,2 16,3 Ошибка цитирования Неверный тег <ref>; для сносок DataIO_1980_OG не указан текст
  17. 17,0 17,1 17,2 Ошибка цитирования Неверный тег <ref>; для сносок DataIO_1987_TFF не указан текст
  18. 18,0 18,1 18,2 Ошибка цитирования Неверный тег <ref>; для сносок Fujitsu_2001 не указан текст
  19. 19,0 19,1 Ошибка цитирования Неверный тег <ref>; для сносок DRI_1982_CPM-M не указан текст
  20. 20,0 20,1 20,2 Ошибка цитирования Неверный тег <ref>; для сносок Intel_1974_PLM не указан текст
  21. 21,0 21,1 21,2 21,3 Ошибка цитирования Неверный тег <ref>; для сносок Hennig-Roleff_1993 не указан текст
  22. Ошибка цитирования Неверный тег <ref>; для сносок GeorgG_2021 не указан текст
  23. 23,0 23,1 Ошибка цитирования Неверный тег <ref>; для сносок Intel_1979_2920 не указан текст
  24. 24,0 24,1 Ошибка цитирования Неверный тег <ref>; для сносок Formaniak-Leitch_1977 не указан текст
  25. 25,0 25,1 25,2 25,3 Ошибка цитирования Неверный тег <ref>; для сносок Ogdin-Colvin-Pittman-Tubb_1977 не указан текст
  26. 26,0 26,1 Ошибка цитирования Неверный тег <ref>; для сносок Kreidl_1981 не указан текст
  27. Ошибка цитирования Неверный тег <ref>; для сносок Rüger_2022 не указан текст
  28. Ошибка цитирования Неверный тег <ref>; для сносок Bull-Dean-Rüger-Wunsch_2023 не указан текст
  29. Ошибка цитирования Неверный тег <ref>; для сносок Xilinx_2010_MCS не указан текст
  30. 30,0 30,1 Ошибка цитирования Неверный тег <ref>; для сносок Beckler_2016 не указан текст
  31. 31,0 31,1 Ошибка цитирования Неверный тег <ref>; для сносок BBC_2021_Universal не указан текст
  32. Ошибка цитирования Неверный тег <ref>; для сносок Intel_1973_Intellec8 не указан текст
  33. Ошибка цитирования Неверный тег <ref>; для сносок Intel_1974_MOD8 не указан текст
  34. Ошибка цитирования Неверный тег <ref>; для сносок Intel_1988_DevTools не указан текст
  35. Ошибка цитирования Неверный тег <ref>; для сносок Kanda_2012 не указан текст
  36. Ошибка цитирования Неверный тег <ref>; для сносок Microchip_2018 не указан текст
  37. Ошибка цитирования Неверный тег <ref>; для сносок Kildall_1978 не указан текст
  38. Ошибка цитирования Неверный тег <ref>; для сносок Zschocke_1987 не указан текст
  39. Ошибка цитирования Неверный тег <ref>; для сносок Prior_1989 не указан текст
  40. 40,0 40,1 40,2 Ошибка цитирования Неверный тег <ref>; для сносок Microchip_1994 не указан текст
  41. Ошибка цитирования Неверный тег <ref>; для сносок Lucid_INHX8M не указан текст
  42. Ошибка цитирования Неверный тег <ref>; для сносок Lucid_INHX32 не указан текст
  43. Ошибка цитирования Неверный тег <ref>; для сносок Paul_1992 не указан текст