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 directive - warning #1119-D: this assembly directive potentially unsafe inside a function

Hi,

In the function _c_int00, I need to work with the value of a global defined variable in a different .C file.
My idea is to store it's value into one CPU register and then restore it to it's original location after the global variables initialisation.
I know that there is a linker option to avoid the initialisation of the global variables, but I can not use it for the moment (--zero_init=off).

For that I'm doing the following implementation that works as expected but generates a warning message:

Texas Instruments TMS470 Code Generation Tools Version 4.9.0
----------------------------------------------------------------------------------------------------------------------------
asm ("    .global TestVar00");   /*External global variable defined in a different C file*/

#pragma INTERRUPT(_c_int00, RESET)   
void _c_int00 (void)
{

   /*Operations using AddressTestVar00 and working with CPU registers in assembly */
  ... store the TestVar00 value into a cpu register
  ...

  /*Initialisation of copy tables and global variables*/
  ...
  ...
  ...

   /*Operations using AddressTestVar00 and working with CPU registers in assembly */
  ... restore the TestVar00 value from a cpu register
  ...

    /* call the application */
    main();
    
    asm ("AddressTestVar00 .word TestVar00");   /*WARNING #1119-D*/
}
----------------------------------------------------------------------------------------------------------------------------
From the map file:
local     AddressTestVar00 (.text:retain)

And I get the following warning:

warning #1119-D: this assembly directive potentially unsafe inside a function

So I tried to move the line that produces the warning outside from the C function but it does not work, as seems that "AddressTestVar00" is created in a different section:
From the map file:
local     AddressTestVar00 (.text)

And I get the following ERRORS(the compilation fails):

 [E0001] Address must be defined in the current section
            ldr   r10,  AddressTestVar00

 [E0004] Illegal operand
            ldr   r10,   AddressTestVar00

Could you please help me to clarify the following items:

1. Why is that assembly directive potentially unsafe inside a function??
2. How could I fix my implementation to avoid that potentially unsafe situation?? (I do not want to suppress the warning message)

Thanks

  • If main() ever returns you would be in trouble since the "asm" insertion is not an executable instruction.  If I understand your requirement correctly, you don't need to resort to assembly language.  Try at file scope (before the _c_int00 function):

    extern far unsigned TestVar00;

    /*static*/ unsigned *AddressTestVar = &TestVar00;

    (If you're using COFF, any assembly code you use may need to include an underscore in front of those names.)

    Within the _c_int00 function, do this before the initialization loops:

        register unsigned save = TestVar00;

    And this before calling main():

        TestVar00 = save;