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.

Word alignemt?

Hi,

how works the word load from memory.

I do the folloing code:

    pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS);
    ulTest = *pulMemory;
    pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS+1);
    ulTest = *pulMemory;
    pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS+2);
    ulTest = *pulMemory;
    pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS+3);
    ulTest = *pulMemory;

And ulTest has everytime the same value.

Why? And how can I change this?

MfG

  • Hello,

    You may try to write "volatile Uint32 *" instead of "Uint32 *". Otherwise the compiler may simplify the source, keeping only the two last lines.

    If not enough, can you display the disassembly window for this code ?

    Jakez

  • Hi,

    nothing happens if I use volatile. Same problem.

    pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS);
              C$L6, C$RL15:
    1180dd84:   0200A35A            MVK.L2        0,B4
    1180dd88:   0240006A            MVKH.S2       0x80000000,B4
    1180dd8c:   9E45                STW.D2T2      B4,*B15[16]
     73           ulTest = *pulMemory;
    1180dd8e:   7246                MV.L1X        B4,A3
    1180dd90:   018C0264            LDW.D1T1      *+A3[0],A3
    1180dd94:   EDB5                STW.D2T1      A3,*B15[15]
     74           pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS+1);
    1180dd96:   2641                ADD.L2        B4,1,B4
    1180dd98:   9E45                STW.D2T2      B4,*B15[16]
     75           ulTest = *pulMemory;
    1180dd9a:   7246                MV.L1X        B4,A3
    1180dd9c:   ED100000            .fphead       p, l, W, BU, nobr, nosat, 1101000
    1180dda0:   018C0264            LDW.D1T1      *+A3[0],A3
    1180dda4:   EDB5                STW.D2T1      A3,*B15[15]
     76           pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS+2);
    1180dda6:   2641                ADD.L2        B4,1,B4
    1180dda8:   9E45                STW.D2T2      B4,*B15[16]
     77           ulTest = *pulMemory;
    1180ddaa:   7246                MV.L1X        B4,A3
    1180ddac:   018C0264            LDW.D1T1      *+A3[0],A3
    1180ddb0:   EDB5                STW.D2T1      A3,*B15[15]
     78           pulMemory = (Uint32 *)(DSPARM_SHAREDRAMADRESS+3);
    1180ddb2:   2641                ADD.L2        B4,1,B4
    1180ddb4:   9E45                STW.D2T2      B4,*B15[16]
     79           ulTest = *pulMemory;
    1180ddb6:   104D                LDW.D2T2      *B4[0],B4
    1180ddb8:   023DE2F6            STW.D2T2      B4,*+SP[15]
    1180ddbc:   E6D00000            .fphead       p, l, W, BU, nobr, nosat, 0110110

    MfG

  • Hi,

    I think you missunderstand me. I incremented my memory address in bytes and make an word access to this address. The memory never changed. If I access this pointer the value in the register should be diffrent every increment.

    regards

  • Hello,

    Oops, my fault...

    The compiler assume Uint32 are always 32-bit aligned (uses LDW, which ignores the 2 least significant bits).

    You have to use intrinsics (_mem4) to force unaligned instruction implementation (ie LDNW or STNW, except for early C6000 cores), see "Using unaligned data" in compiler user's guide (spru187t.pdf).

    Jakez

  • Another approach is to assemble the word from bytes:

    unsigned data = 0; int i; for(i=0;i<4;++i) data |= *((unsigned char *)base_address+i) << (i*8);

    You can easily adapt this to construct a 32-bit datum from an array of bytes that are presented in big-endian order (little-endian was assumed above).