What is the difference between big-end mode and small-end mode?
Editor to share with you what is the difference between the big-end model and the small-end model, I believe that most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!
The difference: the high bytes of the word data in the large-end mode are stored in the low address, while the low bytes of the word data are stored in the high address; while in contrast to the large-end storage mode, in the small-end storage mode, the low address stores the low bytes of the word data, and the high address stores the high bytes of the word data.
The difference between big-end mode and small-end mode
In the C language, in addition to the 8-bit char type, there are 16-bit char type and 32-bit long type (depending on the compiler). For processors with more than 8 bits, such as 16-bit or 32-bit processors, because the register width is greater than one byte, then there must be the problem of how to arrange multiple bytes. This leads to large-end storage mode and small-end storage mode.
Big-end mode:
The high bytes of word data are stored in the low address, while the low bytes of word data are stored in the high address.
Small end mode:
Contrary to the large-end storage mode, in the small-end storage mode, the low address stores the low bytes of the word data and the high address stores the high bytes of the word data.
For example, the 16-bit wide number 0x1234 is stored in the small-end mode CPU memory (assuming it starts with the address 0x4000) as follows:
Memory address
0x4000
0x4001
Store content
0x34
0x12
The storage method in large-end mode CPU memory is as follows:
Memory address
0x4000
0x4001
Store content
0x12
0x34
The storage method in large-end mode CPU memory is as follows:
Memory address
0x4000
0x4001
0x4002
0x4003
Store content
0x12
0x34
0x56
0x78
Our commonly used X86 architecture is small-end mode, while KEIL C51 is large-end mode. Many ARM,DSP are in small-end mode. Some ARM processors can also be chosen by the hardware to be in large-end mode or small-end mode.
Note: large-end data storage is in line with human normal thinking, while small-end data storage is beneficial to computer processing.
(my understanding: the small end mode puts a low bit in the low byte)
The following code can be used to test whether your compiler is in large-end mode or small-end mode:
Int main () {short int xposichar x0rex1section0x1122witx0address * ((char*) & x); / / low address unit, or ((char*) & x) [0]; x1address * ((char*) & x + 1); / / high address unit, or (char*) & x) [1]; printf ("x0address% x\ nx1=%x\ n", x0mom x1);}
If x0=0x11, it is the big end; if x0=0x22, it is the small end.
The above is all the content of this article entitled "what is the difference between big-end mode and small-end mode". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!