XCP中的motorola intel字节序介绍

在Vector的XCP代码中字节序的配置代码如下:

#if defined ( XCP_CPUTYPE_BIGENDIAN )
    CRM_CONNECT_COMM_BASIC |= (vuint8)PI_MOTOROLA;
#endif

说明摩托罗拉字节序其实对应的就是大端字节序,同理intel字节序就对应于小端字节序。

摘录一段wiki上面对大小端的介绍:

In big-endian format, whenever addressing memory or sending/storing words bytewise, the most significant byte—the byte containing the most significant bit—is stored first (has the lowest address) or sent first, then the following bytes are stored or sent in decreasing significance order, with the least significant byte—the one containing the least significant bit—stored last (having the highest address) or sent last.

Little-endian format reverses this order: the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address). Most computer systems prefer a single format for all its data; using the system's native format is automatic. But when reading memory or receiving transmitted data from a different computer system, it is often required to process and translate data between the preferred native endianness format to the opposite format.

翻译过来就是:大端格式指,在按字节存储或者发送数据时,高有意义字节会先发送或者先存储(存储时地址是由低向高增长)。比如我们发送一个32位的数0xFEBD025E,在这个32位的数中FE这个字节就是高有意义(或者高有效)字节,所以在以大端传时,FE会先发出来,然后才是BD025E,接受端在收到这个32位的数后,假设要用大端存储在flash中,那么,FE就会存在低地址处,然后地址加1存BD,依次存025E。

猜你喜欢

转载自blog.csdn.net/hannimao/article/details/85785799