*((int *)&Buf[2]) = 0x12345678;

RVMDK v3.00a, Hello World sample for RealView compiler

#pragma pack(1)

unsigned char Buf[40];

int main (void)
{
*((short int *)&Buf[0]) = 0x77ff;
*((int *)&Buf[2]) = 0x12345678;
/* initialize the serial interface */
PINSEL0 = 0x00050000;
U1LCR = 0x83;
U1DLL = 97;
U1LCR = 0x03;

printf ("Hello World\n");
printf("%x %x %x %x \n", Buf[0],Buf[1],Buf[2],Buf[3]);
}

Hello World

78 56 34 12
------------
The same thing is for CARM compiler 2.4, 2.5

What I am wrong ?

Parents
  • From the 'ARM Architecture Reference Manual':

    ARM processors support the following data types:
    - Byte 8 bits
    - Halfword 16 bits (halfwords must be aligned to two-byte boundaries)
    - Word 32 bits (words must be aligned to four-byte boundaries)

    You are trying to write a word to an address location which is not aligned to a 4-byte boundary. I'm not sure what pragma pack(1) is supposed to do. I suspect it has something to do with structure packing and padding bytes. In other words, pragma pack(1) will not solve this problem.

    - mike

Reply
  • From the 'ARM Architecture Reference Manual':

    ARM processors support the following data types:
    - Byte 8 bits
    - Halfword 16 bits (halfwords must be aligned to two-byte boundaries)
    - Word 32 bits (words must be aligned to four-byte boundaries)

    You are trying to write a word to an address location which is not aligned to a 4-byte boundary. I'm not sure what pragma pack(1) is supposed to do. I suspect it has something to do with structure packing and padding bytes. In other words, pragma pack(1) will not solve this problem.

    - mike

Children
More questions in this forum