Keil Logo

Inline Assembly

The extended inline assembler merges assembly instructions with the assembly code generated by the compiler and creates an object file. There is nothing to assemble with the AARM Assembler.

Extended inline assembler blocks begin with the __asm keyword. For example:

__asm { instruction ; comment }

__asm {               ; open inline-assembly block
       instruction    ; comment
      }               // close inline-assembly block


instruction Is an instruction opcode.
comment Is a program comment.

For example:

int AddUp (
  int n,
  int *pTab)
if (n == 0) return(0);

  mov   r0, #0       ; clear result
  ldav  r2, r0, pTab  ; R2=start of table
  ldav  r3, r0, n     ; R3=table length
  lsl   r3, r3, #2
  sub   r3, #4
  ldr   r1, [r2,r3]
  add   r0, r1
  cmp   r3, #0        ; end of table ?
  bgt   lM            ; loop if not eot
// Return Value in R0


  • __asm blocks may not be nested.
  • __asm blocks may not be used outside a function definition.
  • Labels may be defined in an __asm block and may be referenced by assembler B instructions or the C goto statement. An assembler label defined within an __asm block is equivalent to a C label defined in a C function. C labels may be referenced by B instructions in __asm blocks.

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.