32-bit ARM write-in operation with no memory-aligned assignment

Source: Internet
Author: User

With the 32-bit ARM7 chip lpc2129 and Keil compilers, the problems encountered in project development are as follows:

To define a byte array:

BYTE array[10] = {0};


Then cast the address &array[1] and assign the value:

* (UINT16 *) (&array[1]) = 0xaabb;


Then read the contents of the array, found that the assigned element is array[0] and array[1], read the content is:

Array[0] content is 0XBB, array[1] content is 0xaa,array[2]-array[9] are 0.


is very puzzled. Should not be assigned should be array[1] and array[2]?

So I ran these lines of code with VS2008 on my PC and found that I was assigned array[1] and array[2] (this is what I expected).

Then I tried it again in arm + Keil, gave &array[2] cast and assigned value, found that I expected, was assigned to array[2] and array[3].


Thinking:

1, this should not be the size of the end of the problem.

2, if the problem is the memory force alignment, the 32-bit CPU accesses memory can only access the address of an integer multiple, but the Keil compiler should make the statement as multiple store (write) command, and then calculate a corresponding value to put the corresponding address ah.


I'll see the corresponding assembly code tomorrow. See you tomorrow.




32-bit ARM write-in operation with no memory-aligned assignment

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.