1. What is big end and what is small end

The so-called big end mode means that the low bit of data is stored in the high address of memory, while the high bit of data is stored in the low address of memory;

The so-called small end mode means that the low bits of the data are stored in the low address of the memory, while the high bits of the data are stored in the high address of the memory.

2. Why are there big and small ends

Why are there big and small end models? This is because in the computer system, we are in bytes, each address unit corresponds to a byte, a byte is 8bit. However, in C language, in addition to 8bit char, there are 16bit short and 32bit long (depending on the specific compiler). In addition, for processors with more than 8 bits, such as 16 bit or 32-bit processors, because the register width is larger than one byte, there must be a problem of arranging multiple bytes. Therefore, it leads to the big end storage mode and the small end storage mode. For example, if a 16 bit short type X has an address of 0x0010 in memory and the value of X is 0x1122, then 0X11 is a high byte and 0x22 is a low byte. For the big end mode, we put 0X11 in the low address, that is, in 0x0010, and 0x22 in the high address, that is, in 0x0011. Small end mode, just the opposite. Our commonly used x86 structure is small end mode, while keil c51 is large end mode. Many arm, DSP are small end mode. Some ARM processors can also be selected by hardware whether it is large end mode or small end mode.

3. Examples of storage methods of large and small end in memory:

For example, the storage method of the 16bit wide number 0x1234 in the memory of the little endian mode CPU (assuming that it is stored from the address of 0x4000) is:

What is the big end and the small end

4. How to test whether the compiler is big end or small end:

The following code can be used to test whether your compiler is in big end mode or small end mode:

#include

int main()

{

short int x;

char x0,x1;

x=0x1122;

X0 = ((char *) & x) [0]; / / low address unit

X1= ((char *) &x) [1]; / / high address unit

Printf (“x0 = 0x% x, X1 = 0x% X”, x0, x1); / / if x0 = 0X11, it is the big end; if x0 = 0x22, it is the small end

return 0;

}

The following is the result of running in dev C + +. From the result, dev C + + uses small end mode;

What is the big end and the small end

Leave a Reply

Your email address will not be published. Required fields are marked *