Keil™, An ARM® Company

C166 User's Guide

Extended 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 A166 Assembler (unlike Traditional Inline Assembly).

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

Where

instructionIs an instruction opcode.
commentIs a program comment.

For example:

int AddUp (
  int n,
  int near *pTab)
{
  __asm  {            ; open inline-assembly block
    mov   r2,pTab     ; R2:=start of table
    mov   r3,n
    cmp   r3,#0
    jmp   cc_sle,stop ;
    shl   r3,#1       ; n * 2
    add   r3,r2       ; R3 := (n*2)+pTab, end of table + 2
    mov   r4,#0x00    ; clear result

lM: add   r4,[r2+]    ; add up next value
    cmp   r2,r3       ; end of table ?
    jmp   cc_nz,lM    ; loop if not eot
    ret               ; need result in R4
  }

stop:
  __asm { nop    ; single line assembly }
  __asm { nop    ; another nop          }
  return (0);
}

Note

  • __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 JMP 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 JMP instructions in __asm blocks.