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.

C variable used in .asm

Other Parts Discussed in Thread: TMS570LC4357

Hello CCS Forum Team

I use TMS570LC4357 Launchpad with CCS Version: 6.1.1.00022.

Please let me know how to pass the address of a global variable declared in C to Stack pointer in an .asm code.

Here is how I tried to link

In .C

uint32 g_sys_backup_u32[8388608] __attribute__((section(".sdram")));

 

In .asm

LDR  SP,[g_sys_backup_u32]

 

Please let me know if this is a right way or the syntax is different?

Thanks in advance!

  • The C code is fine.  In assembly try this ...

            .global g_sys_backup_u32
            MOVW    SP, g_sys_backup_u32
            MOVT    SP, g_sys_backup_u32

    I know that builds clean.  And I'm confident is it correct.  But I didn't run it.

    Thanks and regards,

    -George

  • George Mock said:

    The C code is fine.  In assembly try this ...

            .global g_sys_backup_u32
            MOVW    SP, g_sys_backup_u32
            MOVT    SP, g_sys_backup_u32

    I know that builds clean.  And I'm confident is it correct.  But I didn't run it.

    What if interrupt strikes between these two instructions? Or in other words it's probably more correct to compose the value in register other than SP and then move it to SP with single instruction. It might also be appropriate to remind that stack customarily grows toward lower addresses, so that actually pointing at g_sys_backup_u32 is not necessarily the right thing to do, one should rather point at the end of that array. And of course just like with above snippet it would be a mistake to move pointer to g_sys_backup to SP and then adjust it to point at the end of array. Even that is better performed in another register...

  • You can use the variable somewhere a function in the C file and compile it with option "Keep generated assembly file". Then, check the generated assembly code. Now, you will know how the compiler uses the variable in assembly. You can use it at the same way.