This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C6000 指针访问非对齐地址



最近在调试程序的时候发现一个问题,于是用simulator仿真测试了一个程序,通过unsigned int 型指针指向非对齐地址,程序如下:

unsigned int *ptr  = 0x70000001;

*ptr = 0x12345678;

实际上,程序修改的是0x70000000,0x70000001,0x70000002,0x70000003,这几个地址,而不是我想要的0x70000001,0x70000002,0x70000003,0x70000004这几个地址。这样的话,我现在指针强制转换都不太敢用了。

我想请问这个是汇编进行了相应处理,还是CPU自己处理的 

main:
0720c86c: 01BE14F6 STW.D2T2 B3,*B15--[16]
68 unsigned int *ppp = (unsigned int *)0x70000001;
0720c870: 020000AA MVK.S2 0x0001,B4
0720c874: 0238006A MVKH.S2 0x70000000,B4
0720c878: BCC5 STW.D2T2 B4,*B15[5]
77 *ppp = 0xffffffff;
0720c87a: FEA7 MVK.L2 -1,B5
0720c87c: E8300000 .fphead p, l, W, BU, nobr, nosat, 1000001b
0720c880: 029002F6 STW.D2T2 B5,*+B4[0]

以上是c语言对应的汇编代码,没看出什么究竟啊?

请帮忙解答一下

  • 这个是编译器要求的。对于unsigned int 数据类型,要求aligned to 32-bit boundary,请参考下面的编译器手册第188页。

    Table 7-1. Data Representation in Registers and Memory
    http://www.ti.com/lit/ug/spru187u/spru187u.pdf