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 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.

The compiler does not track the assembler instructions inserted in ASM/ENDASM sections. To prevent from generating incorrect programs, the user must be aware of the following side effects and consider this in the inserted assembler code.

  • The compiler tracks registers of functions, but not of the instructions inserted in ASM/ENDASM sections. When registers are modified in such sections, the registers must be saved and restored in the inserted assembler code to avoid conflicts with the compiler generated register assignment.
  • The compiler avoids to reload variable contents, but does not track variable modifications done by instructions inserted in ASM/ENDASM sections. When a variable is modified in such sections, this variable should be defined using the volatile attribute, which prevents the compiler from optimizing for register accesses.

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.
  • 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
  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.