Computer size end

Source: Internet
Author: User

Big end Mode

The so-called Big-end mode refers to the high data index, which is stored in the low address of the memory, while the low data level is stored in the high address of the memory, this storage mode is similar to processing data as strings: The address increases from small to large, and the data is placed from high to low;

Example: 0000430: e684 6c4e 0100 1800 53ef 0100 0100 0000: b484 6c4e 004e ed00 0000440 0000 0000 0100 in large-end mode, the first 16 digits should read: e684

Memory method:
The order of address growth is opposite to that of value growth.


Small-end Mode
The so-called small-end mode stores high data records in the memory address, while low data records in the memory address, this storage mode effectively combines the high and low addresses with the data bit permissions. The high address part has a high weight, and the low address part has a low weight, which is consistent with our logic method.

Example: 0000430: e684 6c4e 0100 1800 53ef 0100 0100 0000: b484 6c4e 004e ed00 0000440 0000 0000 0100 in Small-end mode, the first 16 digits should read: 84e6

Memory method:
The order of address growth is the same as that of value growth.


Why are there differences between large and small models?

Why are there differences between large and small models? This is because in computer systems, we use bytes. Each address unit corresponds to one byte, and each byte is 8 bit. However, in C language, apart from 8-bit char, there are 16-bit short and 32-bit long (depending on the specific compiler). In addition, for a processor whose digits are greater than 8 bits, for example, for a 16-bit or 32-bit processor, because the register width is greater than one byte, there must be a problem of how to arrange multiple bytes. Therefore, the large-end storage mode and the Small-end storage mode are created. For example, if the address of a 16-bit short X in the memory is 0x0010 and the value of X is 0x1122, 0x11 is a high byte and 0x22 is a low byte. For
In the big-end mode, place 0x11 in the low address, that is, 0x0010, and 0x22 in the high address, that is, 0x0011. The small-end mode is the opposite. The commonly used X86 architecture is the small-end mode, while the Keil C51 mode is the large-end mode. Many arm and DSP are in small-end mode. Some arm processors can also choose big-end mode or small-end mode from hardware.

Test the editor Mode

The following code can be used to test whether your compiler is a large-end mode or a small-end mode:

Short int X;

Char x0, x1;

X = 0x1122;

X0 = (char *) & X) [0]; // low address Unit

X1 = (char *) & X) [1]; // If X0 = 0x11, the high-end unit is large. If X0 = 0x22, it's a small client ......

The above program can also see that data addressing uses a low byte address.

Determine the size of a Linux operating system:

Static Union

{

Char C [4];

Unsigned long l;

} Endian_test = {'l ','? ','? ',' B '}};

# Define endianness (char) endian_test.l)

(If endianness = 'l', the system is little endian, and 'B' indicates big endian ).

Use C language to determine the processor size

[1] int checkcpu ()

{

Union W

{

Int;

Char B;

} C;

C. A = 1;

Return (C. B = 1);/* 1: Little-Endian * // * 0: Big-Endian */

}

# Include <stdio. h>

Int main (void)

{

Int A = 0x12345678;

Unsigned char * P =

(Unsigned char *) &;

If (0x78 = * P)

{

Printf ("littleend \ n ");

}

Else

{

Printf ("bigend \ n ");

}

Return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.