很多人都不清楚HEX文件格式

Intel HEX文件是由一行行符合Intel HEX文件格式的文本所构成的ASCII文本文件。在Intel HEX文件中,每一行包含一个HEX记录。这些记录由对应机器语言码和/或常量数据的十六进制编码数字组成。Intel HEX文件通常用于传输将被存于ROM或者EPROM中的程序和数据。大多数EPROM编程器或模拟器使用Intel HEX文件。

#HEX记录格式

Intel HEX由任意数量的十六进制记录组成。每个记录包含5个域, 它们按以下格式排列[:LLAAAATT[DD…]CC]。每一组字母对应一个不同的域, 每一个字母对应一个十六进制编码的数字。每一个域由至少两个十六进制编码数字组成, 它们构成一个字节。

详细解释如下:

每个Intel HEX记录都由冒号开头。

LL是数据长度域,它代表记录当中数据字节(dd)的数量。

AAAA是地址域,它代表记录当中数据的起始地址。

TT是代表HEX记录类型的域,它可能是以下数据当中的一个:

00 – 数据记录

01 – 文件结束记录

02 – 扩展段地址记录

04 – 扩展线性地址记录

DD 是数据域,它代表一个字节的数据。一个记录可以有许多数据字节,记录当中数据字节的数量必须和数据长度域LL中指定的数字相符。

CC是校验和域,它表示这个记录的校验和。校验和的计算是通过将记录当中所有十六进制编码数字对的值相加,以256为模进行以下补足。也就是说LLAAAATT[DD…]CC一共的校验和永远为0。

#数据记录格式

Intel HEX文件由任意数量以回车换行符结束的数据记录组成.

数据记录外观如下:

[:10246200464C5549442050524F46494C4500464C33]

其中:

10是这个记录当中数据字节的数量。

2462 是数据将被下载到存储器当中的地址。

00是记录类型(数据记录)。

464C…464C是数据。

33 是这个记录的校验和的补足码。

#扩展线性地址记录(HEX386)格式

扩展线性地址记录也叫作32位地址记录或HEX386记录。这些记录包含数据地址的高16位。扩展线性地址记录总是有两个数据字节。

外观如下:

[:02000004FFFFFC]

其中:

02是这个记录当中数据字节的数量。

0000是地址域,对于扩展线性地址记录,这个域总是0000。

04是记录类型 04(扩展线性地址记录)。

FFFF是地址的高16位。

FC是这个记录的校验和的补足码。

当一个扩展线性地址记录被读取,存储于数据域的扩展线性地址被保存,它被应用于从Intel HEX文件读取来的随后的记录。线性地址保持有效,直到它被另外一个扩展地址记录所改变。

通过把记录当中的地址域与被移位(16位)的来自扩展线性地址记录的地址数据相加获得数据记录的绝对存储器地址。以下的例子演示了这个过程:

来自数据记录地址域的地址                2462 扩展线性地址记录的数据域*10000H  +  FFFF0000 --------------------- 绝对存储器地址                      FFFF2462

#扩展段地址记录(HEX86)

扩展段地址记录也叫HEX86记录,它包括4-19位数据地址段。扩展段地址记录总是有两个数据字节。

外观如下:

[:020000021200EA]

其中:

02 是记录当中数据字节的数量。

0000是地址域,对于扩展段地址记录,这个域总是0000。

02是记录类型 02(扩展段地址记录)

1200是地址段。

EA是这个记录的校验和的补足码。

当一个扩展段地址记录被读取,存储于数据域的扩展段地址被保存,它被应用于从Intel HEX文件读取来的随后的记录。段地址保持有效,直到它被另外一个扩展地址记录所改变。

通过把记录当中的地址域与被移位(4位)的来自扩展段地址记录的地址数据相加获得数据记录的绝对存储器地址。以下的例子演示了这个过程:来自数据记录地址域的地址         2462

扩展段地址记录数据域*10H    +   12000 ----------------- 绝对存储器地址               00014462

#文件结束(EOF)记录。

Intel HEX文件必须以文件结束(EOF)记录结束。这个记录的记录类型域的值必须是01。EOF记录外观总是如下

[:00000001FF]

其中:

00是记录当中数据字节的数量。

0000是数据被下载到存储器当中的地址。在文件结束记录当中地址是没有意义被忽略的。0000H是典型的地址。

01是记录类型01(文件结束记录)

FF是这个记录的校验和的补足码。

#Intel HEX文件例子

下面是一个完整的Intel HEX文件的例子:

:10001300AC12AD13AE10AF1112002F8E0E8F0F2244
:10000300E50B250DF509E50A350CF5081200132259
:03000000020023D8
:0C002300787FE4F6D8FD7581130200031D
:10002F00EFF88DF0A4FFEDC5F0CEA42EFEEC88F016
:04003F00A42EFE22CB
:00000001FF

看了这个例子,我自己也打开了之前写的51单片机的hex文件:

:2000000002000E75210675225B75230200267B007C00900090758140758901758CF1758A45
:2000200028D28C75A882758CF1758A280BBBFA157B00EC75F00A8485F020F5210CBC64027A
:200040007C00120051C0E0C0D0120051D0D0D0E032E52193F580D2A2C2A27580FED2A3C29C
:20006000A3120087E52093F580D2A2C2A27580FDD2A3C2A3120087227D327E287FF81151AA
:1A008000DFFEDEF8DDF4227E047FF8DFFEDEFA223F065B4F666D7D077F6FBC
:00000001FF

#英文原文

QUESTION:What is the Intel HEX file format?
ANSWER:
8.1 The Intel HEX file is an ASCII text file with lines of text that follow theIntel HEX file format. Each line in an Intel HEX file contains one HEX record.These records are made up of hexadecimal numbers that represent machine language code and/or constant 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 Intel HEX files.
8.2 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:
8.2.1 : is the colon that starts every Intel HEX record.
8.2.2 LL is the record-length field that represents the number of data bytes (dd) in the record.
8.2.3 AAAA is the address field that represents the starting address for subsequent data in the record.
8.2.4 TT is the field that represents the HEX record type, which may be one of the following:
8.2.4.1 00 - data record
8.2.4.2 01 - end-of-file record
8.2.4.3 02 - extended segment address record
8.2.4.4 04 - extended linear address record
8.2.5 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.
8.2.6 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.
8.3 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
where:
8.3.1 10 is the number of data bytes in the record.
8.3.2 2462 is the address where the data are to be located in memory.
8.3.3 00 is the record type 00 (a data record).
8.3.4 464C...464C is the data.
8.3.5 33 is the checksum of the record.
8.4 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:
8.4.1 02 is the number of data bytes in the record.
8.4.2 0000 is the address field. For the extended linear address record, this field is always 0000.
8.4.3 04 is the record type 04 (an extended linear address record).
8.4.4 FFFF is the upper 16 bits of the address.
8.4.5 FC is the checksum of the record and is calculated as 01h + NOT(02h + 00h + 00h + 04h + FFh + FFh).
8.4.6 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.
8.4.7 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      2462Extended linear address record data field     FFFF-----------
Absolute-memory address                 FFFF2462
8.5 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
where:
8.5.1 02 is the number of data bytes in the record.
8.5.2 0000 is the address field. For the extended segment address record, this field is always 0000.
8.5.3 02 is the record type 02 (an extended segment address record).
8.5.4 1200 is the segment of the address.
8.5.5 EA is the checksum of the record and is calculated as 01h + NOT(02h + 00h + 00h + 02h + 12h + 00h).
8.5.6 When an extended segment address record is read, the extended segment addressstored 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.
8.5.7 The absolute-memory address of a data record is obtained by adding the addressfield 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
8.6 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
where:
8.6.1 00 is the number of data bytes in the record.
8.6.2 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.
8.6.3 01 is the record type 01 (an end-of-file record).
8.6.4 FF is the checksum of the record and is calculated as 01h + NOT(00h + 00h + 00h + 01h).
8.7 Example Intel HEX File.
Following is an example of a complete Intel HEX file:
:10001300AC12AD13AE10AF1112002F8E0E8F0F2244
:10000300E50B250DF509E50A350CF5081200132259
:03000000020023D8
:0C002300787FE4F6D8FD7581130200031D
:10002F00EFF88DF0A4FFEDC5F0CEA42EFEEC88F016
:04003F00A42EFE22CB
:00000001FF

#推荐阅读:

    专辑|Linux文章汇总

    专辑|程序人生

    专辑|C语言

嵌入式Linux

微信扫描二维码,关注我的公众号 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/467113.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

小学生算术

</pre><pre> 小学生算术 描述 很多小学生在学习加法时&#xff0c;发现“进位”特别容易出错。你的任务是计算两个三位数在相加时需要多少次进位。你编制的程序应当可以连续处理多组数据&#xff0c;直到输入两个0结束。 输入 输入两个正整数m和n.(m,n都是三位…

如何在asp.net中实现listbox item值上下移动?(转)

全部.net为&#xff1a;1 <form id"myform"runat"server">2 <div>3 <asp:ObjectDataSource ID"ObjectDataSource1"runat"server"OldValuesParameterFormatString"original_{0}"4 …

洛谷1345 [Usaco5.4]奶牛的电信

题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系&#xff0c;于是她们建立了一个奶牛电脑网络&#xff0c;以便互相交流。这些机器用如下的方式发送电邮&#xff1a;如果存在一个由c台电脑组成的序列a1,a2,...,a(c)&#xff0c;且a1与a2相连&#xff0c;a2与a3相连&#xff0c;…

有意思,USB资料分享

前几天&#xff0c;有个同学在微信问我 「发哥&#xff0c;能不能给我分享一些USB的资料吗&#xff1f;」-- 然后就有了今天的文章。我对USB印象很深&#xff0c;源于两个事情第一件事情是&#xff0c;我有一个大学同学&#xff0c;他的名字里面有一个「发」字&#xff0c;我们…

在已经排好序的线性表中插入一个数,还是升序

在已经排好序的线性表中插入一个数&#xff0c;还是升序#include<stdio.h> #define Maxsize 100 typedef struct s {int elem[Maxsize];int last; }Seqlist; int Locate(Seqlist l,int e)//查找 {int i0;while(i<l.last&&l.elem[i]<e)i;if(il.last)return …

java学习笔记IO之字节输入输出流

IO字节输入输出流 OutputStream:字节输出流 该抽象类是所有字节输出流的超类&#xff1b; 定义了一些共性的成员方法&#xff1a; 1.写入一个字节 void write(int b);//b表示字节 2.写入字节数组 void write(byte[] b);//写入一个字节数组 3.写入字节数组的一部分 void write(…

firefox 和 ie 事件处理的细节,研究,再研究-----书写同时兼容ie和ff的事件处理代码...

在ie中&#xff0c;事件对象是作为一个全局变量来保存和维护的。 所有的浏览器事件,不管是用户触发 的&#xff0c;还是其他事件&#xff0c; 都会更新window.event 对象。 所以在代码中&#xff0c;只要轻松调用 window.event 就可以轻松获取 事件对象&#xff0c; 再 event.s…

不知道的,还以为是555牌香烟

你认为历史上最成功的芯片是什么&#xff1f;就是出货很多很多那种。Intel的酷睿系列&#xff1f;NO&#xff01;AMD&#xff1f;错&#xff01;别猜了&#xff0c;原来是它&#xff01;这就是电工的神器——555定时器&#xff0c;从诞生到现在&#xff0c;销量过百亿&#xff…

异形卵

【问题描述】 我们探索宇宙是想了解浩瀚星空的奥秘&#xff0c;我们却很少意识到宇宙深处藏匿的危险&#xff0c;他们无时无刻不紧盯着我们的地球。如果外星人拜访我们&#xff0c;结果可能与哥伦布当年踏足美洲大陆不会有什么两样&#xff0c;这是历史&#xff0c;也是现实。…

C语言书籍推荐

C语言书籍推荐 宗旨&#xff1a;技术的学习是有限的&#xff0c;分享的精神是无限的。 一、基础 1、《C语言入门很简单》 《零起点学通C语言&#xff08;多媒体范例教学&#xff09;》 《C语言从入门到精通》 2、《C程序设计语言 第2版新版》 《C程序设计语言&#xff08;第2版…

SQLServer技巧

-2.批量更新&#xff1a; UPDATE p_ProductTab SET PC4p.pc4 from (select productid030301102000,pc4423523 union all select productid030301102001,pc4sdgser) as pWHERE p_ProductTab.productidp.productid -1.保留2位小数 Convert(decimal(18,2),字段) 长度为18位&…

Linux操作寄存器前为什么要ioremap

1. 原因这里只考虑有 MMU 的芯片&#xff0c;Linux 为了实现进程虚拟地址空间&#xff0c;在启用 MMU 后&#xff0c;在内核中操作的都是虚拟地址&#xff0c;内核访问不到物理地址。如果在驱动里直接访问物理地址&#xff0c;等于访问了一个非法地址&#xff0c;会导致内核崩溃…

Loading页的实现代码

用了几种Loading页的代码&#xff0c;还是算这个好用了。真的佩服牛人们的思想。有的说用DIV来实现遮盖后面的东西&#xff0c;当FORM加载完后&#xff0c;执行CLOSE()d的JS函数。我试验了几次&#xff0c;效果不是那么好。也主要是由于我吧东西都放在我本地&#xff0c;感觉不…

Fibonacci数列

问题描述Fibonacci数列的递推公式为&#xff1a;FnFn-1Fn-2&#xff0c;其中F1F21。 当n比较大时&#xff0c;Fn也非常大&#xff0c;现在我们想知道&#xff0c;Fn除以10007的余数是多少。 输入格式输入包含一个整数n。输出格式输出一行&#xff0c;包含一个整数&#xff0c;表…

C语言——关键字

C语言——关键字 宗旨&#xff1a;技术的学习是有限的&#xff0c;分享的精神是无限的。 【谨记&#xff1a;尽量不要用printf函数&#xff0c;要去看变量的值&#xff0c;内存的值。】 auto&#xff0c;int&#xff0c;double&#xff0c;long&#xff0c;char&#xff0c;fl…

调色板栅格数据使用GDAL时注意

这几天用GDAL处理DRG数据时发现&#xff0c;有数据被处理成了黑板&#xff0c;什么都没有&#xff0c;发现是因为DRG图像颜色比较简单&#xff0c;使用了调色板的缘故。 使用SetColorTable将调色板写入后&#xff0c;一部分基本正常&#xff0c;但还有些图像还是有黑板的现象。…

jQuery实现表格行上移下移和置顶

<!DOCTYPE HTML> <html> <head> <meta charset"utf-8"> <meta name"viewport" content"widthdevice-width, initial-scale1, maximum-scale1"> <title>jQuery实现表格行上移下移和置顶</title> <m…

做算法,为什么建议你一定要学懂C++?

在工业界&#xff0c;有这样一个规律&#xff1a;“ 但凡能用其他语言的都不会用C&#xff0c;只能用C的必然用C。”但是&#xff0c;C的学习和项目开发都比较困难。一个有经验的老手也经常搞出野指针&#xff0c;内存泄露等bug&#xff0c;包括我自己在学C的时候也非常痛苦。所…

顺序查找法

#include<stdio.h> #define KeyType int #define OtherType int #define List_size 100 typedef struct{KeyType key;OtherType other; }RecordType; typedef struct{RecordType r[List_size];int length; }Recordlist; int SeqSearch(Recordlist l,int k)//没有设置监视…