C251 User's Guide

ASM Compiler Directive

Abbreviation

None.

Arguments

None.

Default

None.

µVision

This directive may not be specified on the command line.

Description

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

Note

  • 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 alternate syntax __asm { }.
  • When possible avoid using in-line assembly instructions. Instead use intrinsic functions that are available for most assembler instructions that do not have direct support in the C language.
See Also

ENDASM, SRC

Example
extern void test ();

void main (void)  {
  test ();

#pragma asm
  JMP   $  ; endless loop
#pragma endasm
}