Introduction to big-endian and small-endian modes of tms320c6713

Publisher:qq8174350Latest update time:2011-09-02 Keywords:tms320c6713 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Concept and detailed explanation

There are two main byte storage mechanisms commonly used in computers of various systems: big-endian and little-endian, that is, big-endian mode and little-endian mode.

Let's review two key words first, MSB and LSB:

MSB:Most Significant Bit ------- Most Significant Bit
LSB:Least Significant Bit ------- Least Significant Bit

Big-endian

big-endian: The MSB is stored at the lowest address.

For example, the double-byte number 0x1234 is stored in big-endian format at the starting address 0x00002000:

| data |<-- address
| 0x12 |<-- 0x00002000
| 0x34 |<-- 0x00002001

In Big-Endian, the serial number in the bit sequence is arranged as follows (taking the double-byte number 0x8B8A as an example):

bit | 0 1 2 3 4 5 6 7 | 8 9 10 11 12 13 14 15
------MSB------------------------ ----------LSB
val | 1 0 0 0 1 0 1 1 | 1 0 0 0 1 0 1 0 |
+------------------ --------------------------+
= 0x8 B 8 A

Little-endian

Little-endian: The LSB is stored at the lowest address.

For example, the double-byte number 0x1234 is stored in little-endian format at the starting address 0x00002000:

| data |<-- address
| 0x34 |<-- 0x00002000
| 0x12 |<-- 0x00002001

In Little-Endian, the serial number arrangement in the bit sequence is exactly the opposite of Big-Endian, as follows (taking the double-byte number 0x8B8A as an example):

bit | 15 14 13 12 11 10 9 8 | 7 6 5 4 3 2 1 0
------MSB------------------------ ----------LSB
val | 1 0 0 0 1 0 1 1 | 1 0 0 0 1 0 1 0 |
+----------------- ----------------------------+
= 0x8 B 8 A

2. Storage of arrays in big-endian and small-endian situations:

Take unsigned int value = 0x12345678 as an example, and look at its storage in two byte orders. We can use unsigned char buf[4] to represent value:
Big-Endian: The high bits are stored in the low addresses, as follows:

High address
--------------
buf[3] (0x78) -- Low
buf[2] (0x56)
buf[1] (0x34)
buf[0] (0x12) -- High
---------------
Low address

Little-Endian: The low address stores the low bits, as follows:

High address
--------------
buf[3] (0x12) -- High bit
buf[2] (0x34)
buf[1] (0x56)
buf[0] (0x78) -- Low bit
--------------
low address

3. Big-endian and small-endian conversion method:

Big-Endian is converted to Little-Endian as follows:

#define BigtoLittle16(A) ((((uint16)(A) & 0xff00) >> 8) |
(((uint16)(A) & 0x00ff) << 8))
#define BigtoLittle32(A) ((((uint32 )(A) & 0xff000000) >> 24) |
(((uint32)(A) & 0x00ff0000) >> 8) |
(((uint32)(A) & 0x0000ff00) << 8) |
(((uint32)( A) & 0x000000ff) << 24))

4. Big-endian and small-endian detection methods:

How to check if processor is big-endian or little-endian?

The storage order of the union is that all members are stored starting from the lowest address. This feature can be used to easily obtain whether the CPU uses Little-endian or Big-endian mode to read and write memory .

int checkCPUendian()
{
union
{
unsigned int a;
unsigned char b;
}c;
ca = 1;
return (cb == 1);
}

Keywords:tms320c6713 Reference address:Introduction to big-endian and small-endian modes of tms320c6713

Previous article:Three-phase AC voltage regulation control system for electrostatic precipitator power supply based on single-chip microcomputer 80C196KC
Next article:Implementation of multi-waveform radar signal generator based on AD9957

Recommended ReadingLatest update time:2024-11-17 00:00

Design of high-speed data acquisition system based on DSP and MAX1420
1 Introduction Data acquisition system is an important functional module in the field of communication and information technology, and is widely used. However, most traditional data acquisition systems are based on single-chip microcomputers or medium-scale digital circuits, and their analog-to-digital conv
[Embedded]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号