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.

inline asm function for C program

Hi,

I want to define a inline function for my C program which is composed of asm() instructions.

#pragma FUNC_ALWAYS_INLINE(send_results)
send_results(uint16_t *data, uint16_t size) {
  __asm(" some asm code here");
  __asm(" ...");
}

My requirements:

  • The function has two arguments which should be passed through via registers p.ex. R15 and R14
  • The function has only assembler instructions
  • The function should be compiled inline

FUNC_ALWAYS_INLINE does not inline my C function. How could I define such a inline assembler function?

  • Hi,

    Which device are you using? If MSP430 refer: e2e.ti.com/.../72596

    Regards,
    Gautam
  • Unfortunately, the TI compiler does not support any method which meets your requirements.  Generally speaking, you need GNU C compiler style asm statements.  The TI compiler does not support that feature.

    Thanks and regards,

    -George

  • Yes, I use an MSP430 device.

    I've read the documents mentionend in this post, but could not find the final clue.

    To explain more in detail what I want to achive see the following example:

    void main () {
       // some code before call:
       uint16_t data;
       data = 7;
       send_result(&data, sizeof(data));
       __asm(" asm3");
       ...
    }
    
    void send_result(send_results(uint16_t *data, uint16_t size) {
      __asm(" asm1 R12");
      __asm(" asm2 R13");
    }
    

    The call of send_results() should expand to:

    main:
      ...
      MOV.W SP, R12
      MOV.W #2, R13
      asm1 R12
      asm2 R13
      asm3
    
  • Yes, I solved this for the GCC Compiler already, but I need it for the TI Compiler now. The documents say that local variables could not be used in asm() but in asm functions. For my case send_results() is not necessary a C function, ASM is also ok.
    How could I define a inline asm function?
  • The TI compiler does not support the usage of asm statements in the manner you describe.  What worries me here is that it appears it might work.  And in some isolated cases, it might actually generate code which works.  But, generally speaking, many things can go wrong.  Changing compiler versions, or changing optimization levels, could cause the code to change from working to failing.  The bottom line is you cannot inline an assembly function.

    Have you considered using intrinsics?  An intrinsic acts like a function call, but is implemented in a single instruction (with limited exceptions).  This instruction is often very difficult to model in C.  Please see the section of the compiler manual titled Using Intrinsics to Access Assembly Language Statements.

    Thanks and regards,

    -George