Keil Logo

ASM Compiler Directive








This directive may not be specified on the command line.


The ASM directive signals the beginning of a block of assembler source text to merge into the .SRC file generated using the SRC directive.

The ENDASM directive signals the end of the source text block.

The syntax __asm { } can be used as an alternative to ASM / ENDASM sequences. __asm { JMP $ } is therefore identical with the example below.

The source text can be thought of as in-line assembly. However, it is output to the source file generated only when using the SRC directive.

In µVision you may set a file specific option for C source files that contain ASM/ENDASM sections as follows:

  1. Right click on the file in the Project Window — Files tab
  2. Choose Options for... to open Options — Properties page
  3. Enable Generate Assembler SRC file
  4. Enable Assemble SRC file.

µVision generates an assembler source file (.SRC) and translates this file with the Assembler, which generates an object file (.OBJ). The linker links this object file with other object files from the project and creates the target application program.


  • The ASM and ENDASM directives may occur only in the source file as part of a #pragma.
  • In a ASM/ENDASM only assembler instructions are permitted. Assembler directives and controls are not allowed.
  • To use in-line assembly instructions with #define preprocessor macros, use the alternative syntax __asm { }.
  • When possible, avoid using in-line assembly instructions. Instead, use intrinsic functions available for most assembler instructions that do not have direct support in the C language.
See Also


extern void test ();

void main (void)  {
  test ();

#pragma asm
  JMP   $  ; endless loop
#pragma endasm
#define LOOPFOREVER    __asm { JMP $ }

void main (void)  {

Related Knowledgebase Articles

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.