Keil Logo

Traditional Inline Assembly

The traditional inline assembler merges assembly instructions with the code generated by the compiler and creates assembly source files that you assemble with the A166 Assembler.

The ASM and ENDASM directives enclose the assembly source code and the SRC directive directs the compiler to generate an assembler source file. For example:

#pragma SRC
#pragma SMALL

unsigned int asmfunc1 (
  unsigned int arg)
{
#pragma ASM
INC   R8
#pragma ENDASM

return (arg);
}

For this example, the compiler generates the following SRC file.

$NOMACRO
$SEGMENTED CASE MOD167
;
; '.\asmfunc1.SRC' GENERATED FROM INPUT FILE 'asmfunc1.c'
; COMPILER INVOKED BY:
;       C:\Keil_v5\C166\BIN\C166.EXE asmfunc1.c BROWSE
;        MOD167 DEBUG SRC(.\asmfunc1.SRC)
;
$MODINF (43)
NAME ASMFUNC1
NCODE  CGROUP  ?PR?ASMFUNC1
ASSUME  DPP3 : SYSTEM
REGDEF   R0 - R15

?PR?ASMFUNC1  SECTION  CODE WORD 'NCODE'
; line 1: #pragma SRC
; line 2: #pragma SMALL
; line 3:
; line 4: unsigned int asmfunc1 (

         asmfunc1  PROC  NEAR
         PUBLIC  asmfunc1
; FUNCTION asmfunc1 (BEGIN  RMASK = @0x0010)
;---- Variable 'arg' assigned to Register 'R8' ----
; line 4:   unsigned int arg)
; line 5: {
; line 6: #pragma asm
; line 7: ADD R8,#1
        ADD R8,#1
; line 8: #pragma endasm
; line 9:
; line 10: return (arg);
        MOV     R4,R8
; line 11: }
        RET
; FUNCTION asmfunc1 (END    RMASK = @0x0010)
         asmfunc1  ENDP
?PR?ASMFUNC1  ENDS

END

Note

  • SRC files created using the ASM and ENDASM directives must be compiled using the SRC directive and must be assembled with the A166 Assembler.
  • Source-level information is not available for C files for which a SRC file was generated, assembled, and linked into the project. You may debug the generated assembler code but not the original C source code. If this is a requirement, consider using Extended Inline Assembly.
  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.