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.

Compiler/AWR1843: Access external address in inline assembly

Part Number: AWR1843

Tool/software: TI C/C++ Compiler

Hello,

first, please consider this working example in an assembler file (tooling version is TLS16.9.1), of course only a snippet:

some_c_variable is defined and implemented in a *.c file
local_var .word some_c_variable
;somewhere in assembly code in the same file I can now use e.g.:
LDR R0, local_var

This macro can be used without problem.

Now, I would like to get the same functionality in an inline assembly function, but I failed to access some_c_variable or local_var (if i exported and imported it via .global).

Just for reference, this is something i would like to get working, (this returns [E0001] Undefined symbol )
__asm(" LDR R0, some_c_variable");

Can someone point me in the right direction?
Kind regards,
Christoph

  • You are not using the asm statement in its typical and intended manner.  That being the case, you may create more problems than you solve.  Please search the TI ARM compiler manual for the sub-chapter titled The __asm Statement.  That said ...

    Your C code needs to have a statement similar to ...

    extern int some_c_variable;

    The next bit is tricky.  And it uses the asm statement in a way which is NOT prescribed.  Add an asm statement similar to ...

        __asm("unique_label:    .word    some_c_variable");

    The output of this asm statement needs to appear in the same section as the function which refers to this entry.  But it cannot appear inside the function itself.  Here is where you need to experiment.  Moreover, the behavior of the compiler in this detail is not guaranteed.  It might be different between versions.  Such a difference in behavior is unlikely, but it can happen at any time, with no notice.

    Once that is all in place, then you can issue this asm statement ...

    __asm(" LDR R0, unique_label");

    In closing, I very much dislike this suggested solution.  I view it as a good reason to avoid asm statements.

    Thanks and regards,

    -George

  • Thanks, George, this is working (once I disabled the --gen_func_subsections=on" option).

    Could you tell my why the labels are discouraged by you (and the compiler, as this will show a warning)? Labels are even mentioned in the compiler guide (TLS16.9.1, chapter 5.9: __asm("STR: .byte....

  • In assembly code, the position of one line, relative to the other lines, is very important.  However, you cannot precisely control the position of asm statement.

    Thanks and regards,

    -George