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.

Help for inserting assembly instructions into .c source file...

Hi All,

I am working on ARM processor. I have successfully used following assembly instructions into .asm i.e. assembly source file:
------------------------------------------------------------------------------------------------
LDR  R1, otp_add ; load address 0x00001000 into R1
BLX   R1                  ; branch to location 0x00001000

;***************************************************************
;* CONSTANTS USED BY THIS MODULE
;***************************************************************
        .if !__TI_AVOID_EMBEDDED_CONSTANTS
otp_add          .long    0x00001000
        .endif
------------------------------------------------------------------------------------------------

Now I want to use above assembly instruction into C source file so I used following syntax:
__asm(" otp_add .long 0x00001000\n"
           
" ldr R1, otp_add\n "
          
" blx R1");

However I am getting following errors:
otp_add .long 0x00001000 - [E0002] Illegal mnemonic specified  
ldr R1, otp_add                      -[E0001] Address must be defined in the, [E0001] Undefined symbol

Please let me know correct way to define constants in __asm.

Please Note: I used C syntax like #define otp_add 0x1001 at the start of C source file as well as
const unsigned int otp_add = 0x00001001 at the start of C source file and used following instructions
__asm(" ldr R1, otp_add\n "
          
" blx R1");
however in vain.

Thanks in advance.
Tushar

  • If you remove the space between the opening quote and otp_add, then it will build, though with this diagnostic ...

    "file.c", line 4: warning: this assembly directive potentially unsafe inside a function
    

    The TI ARM compiler and the gcc ARM compiler are very different in how asm statements are handled.  There is very little you can safely do inside TI ARM compiler asm statements.  Any of the following does not work: a long directive, loading a register, branching.

    Thanks and regards,

    -George

  • Hi George,

    You correctly pointed out the problem. Now using following syntax, the errors mentioned in my first post is gone.

    __asm("otp_add .long 0x00001000\n"
               
    " ldr R1, otp_add\n "
              
    " blx R1");

    However, I am getting following error:
    ldr R1, otp_add - [E0200] Offset out of range 

    I thought the address 0x1000 could be out of range so provided "otp_add .long 0x10\n" however getting same error. So it seems to be some syntax related error.

    Please let me know what could be the problem and let me know which document I should refer for syntax.

    Thanks in advance.

    Tushar

  • Try moving the line containing ".long" to the last line of the __asm statement, after the blx instruction.