Several features (concepts) determined by the CPU type

Source: Internet
Author: User

1, variables (such as defining a four-byte variable int var) in the memory of the format is big-endian or small-end?

For example, define a variable int var = 1; If the CPU is a 32-bit CPU, the compiler will assign a value of 4 bytes in memory to 0x01,0x00,0x00,0x00, then the CPU reads in memory according to the address of the variable. This successive 4 bytes into its own register, and then the adder of the CPU adds the 4 bytes of content (as a value of 1). In the case of a big-endian CPU, the compiler assigns a value of 0x00,0x00,0x00,0x01, and then the CPU reads it and uses its own adder (as a number 1) to operate.


Similarly, if the memory of a variable in the address 0~3 content is 0x01, 0x00,0x00, 0x00, if it is a small end of the CPU, then the memory of this 4-byte variable represents the value 1, because this value is the CPU adder as 1 ( Low byte at low address ), if it is a big-endian CPU, then this 4-byte variable in memory represents the value 0x1 00 00 00, because the CPU adder treats it as a value of 0x1 00 00 00 (High byte at low address) to operate.


2, is the stack of threads expanding to a low address or high address?

C language compiler will be the function of parameters, interrupts, task scheduling compiled into the corresponding stack operation push VAR,CPU execute the push var instruction, the contents of the Var to the SP register value refers to the address, while the value of the SP register automatically added 1 or minus 1 (by the CPU type), If the value of the SP register is self-increasing when the CPU executes the push command, then the thread's stack is expanded to a high address, and if it is self-reducing, the thread's stack is expanded to a low address.

Several features (concepts) determined by the CPU type

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.