Basic types of memory storage in X86 architecture, in byte order

Source: Internet
Author: User

This article tests how to store int-type data in x86:The high address bit stores the int's high level, and the low address bit stores the int's low level.This storage method is calledSmall-end format.

There is also the "big-end format ".

 

Read oneProgram:

Code

# Include " Stdio. h "
Void Main ()
{
Int Ival =   65536 ;
Char   * P =   & Ival;
Printf ( " * P: % d \ n " , * P );
Printf ( " * P + 1: % d \ n " , * (P + 1 ));
Printf ( " * P + 2: % d \ n " , * (P + 2 ));
Printf ( " * P + 3: % d \ n " , * (P + 3 ));
Printf ( " * P + 4: % d \ n " , * (P + 4 ));
// Print pointer address
Printf ( " P: % P \ n " , P );
Printf ( " P + 1: % P \ n " , P + 1 );
Printf ( " P + 2: % P \ n " , P + 2 );
Printf ( " P + 3: % P \ n " , P + 3 );
Printf ( " P + 4: % P \ n " , P + 4 );
}

Output result:

* P: 0
* P + 1: 0
* P + 2: 1
* P + 3: 0
* P + 4:-52
P: 0012ff70
P + 1: 0012ff71
P + 2: 0012ff72
P + 3: 0012ff73
P + 4: 0012ff74

Read a exercise question:

Exercise

1 # Include " Stdio. h "
2 Void Main ()
3 {
4 Union { Char A [ 10 ];
5 Int I;
6 } U;
7
8 Int   * P = ( Int   * ) & (U. [ 1 ]); // Note that a [1] is not a [0].
9 * P =   65536 ;
10 Printf ( " U. I = % d \ n " , U. I );
11 Printf ( " U. A [0] = % d \ n " , U. [ 0 ]);
12 Printf ( " U. A [1] = % d \ n " , U. [ 1 ]);
13 Printf ( " U. A [2] = % d \ n " , U. [ 2 ]);
14 Printf ( " U. A [3] = % d \ n " , U. [ 3 ]);
15 Printf ( " U. A [4] = % d \ n " , U. [ 4 ]);
16 }

Output result:

U. I = 16777420
U. A [0] =-52
U. A [1] = 0
U. A [2] = 0
U. A [3] = 1
U. A [4] = 0

Reference for byte order: http://hi.baidu.com/santy/blog/item/0cb6024fd0634730aec3ab09.html

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.