Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.

We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.

Thank you for your understanding.


This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not able to use inline assembly in Keil

I am not able to use inline assembly in my C source file. I tried to Enable Generate Assembler SRC file and Enable Assemble SRC file. Then i used #pragma ASM in the beginning of the assembly code and #pragma ENDASM at the end of the assembly code, but it is not able to recognize even the LDR command. The commands are not recognisable even when i am using __asm() block to write the code. Please advise.

Parents
  • No need to muck about with command line directives.

    This sort of thing works for me:

    static unsigned long SwapU32(unsigned long to_swap)
    {
      const unsigned long mask = 0x00FF00FF;
      unsigned long temp;
    
      __asm {
        AND temp,    mask,    to_swap
        AND to_swap, mask,    to_swap, ROR #24
        ORR to_swap, to_swap, temp,    ROR #8
      }
    
      return (to_swap);
    }
    

    Function extracted from original Keil supplied source.

Reply
  • No need to muck about with command line directives.

    This sort of thing works for me:

    static unsigned long SwapU32(unsigned long to_swap)
    {
      const unsigned long mask = 0x00FF00FF;
      unsigned long temp;
    
      __asm {
        AND temp,    mask,    to_swap
        AND to_swap, mask,    to_swap, ROR #24
        ORR to_swap, to_swap, temp,    ROR #8
      }
    
      return (to_swap);
    }
    

    Function extracted from original Keil supplied source.

Children
No data