Keil Logo

Operators

Operators

The following operators are supported by the extended inline assembler:

Operator Description
% modulo operator
$ current PC offset (example: JMP cc_sgt,$-2)
. bit position operator
, expression separator
# immediate operand operator
: label operator (example: myLab:)
+  -  * / arithmetic operators: addition, subtraction, multiplication, division
(  ) expression precedence grouping
[  ] used for indirect register operators (example: [R0+#0x10])
&  |  ^  ! binary operators: and, or, xor, not
==  !=
<=  <  >=  >
relational operators: equal, not equal,
less or equal, less than, greater or equal, greater than
<<  >> shift operators:  shift left, shift right
PAG page number operator (example: MOV R5,#PAG iTable)
POF page offset operator (example: MOV R4,#POF iTable)
SEG segment number operator (example: MOV R5,#SEG iTable)
SOF segment offset operator (example: MOV R4,#SOF iTable)
SHORT short type override (example: JMP SHORT myLabel)
FAR  NEAR far or near type override (example: CALL FAR Func)
BYTE  WORD type override (example: MOV WORD [R1+],#0x12)
sizeof C like sizeof operator (example:  MOV R3,#sizeof (pTable) * 2 )
HIGH  LOW high or low byte of word operand (example: MOV RL4,#HIGH (SOF iTable) )
BYTE0 BYTE1 BYTE2 BYTE3 byte of word or long operand (example: MOV RL4,#BYTE2 iTable) )
WORD0 WORD2 low or high word of long operand (example: MOV R2,WORD0 xhuge_ptr)

The access to a high or low word of parameters or local symbols of the data types long, unsigned long, far *, huge *, or xhuge * the WORD0 and WORD2 operators must be used. C166 stores far *, huge *, or xhuge * pointers and long values with low word first, then high word. This word order is also true for long values that are assigned to CPU registers and implies that R(n) is low word and R(n+1) is high word.

  • The WORD0 operator gives the low order word and translates either to [R0+#offs] or the low order register of a register variable.
  • The WORD2 operator gives the high order word and translates to [R0+#offs+2] or the high order register of a register variable.

The example below shows how to access long values in __asm blocks:

int XpAddUp (int n, int xhuge *pTab)  {
  __asm  {
    mov   r2,word0 pTab   ; get SOF part of xhuge ptr
    mov   r3,word2 pTab   ; get SEG part of xhuge ptr
    cmp   n,#0            ; count zero ?
    jmp   cc_sle,stop     ; stop if so.
    mov   r4,#0x0000      ; clear result

lM: exts  r3,#1
    add   r4,[r2]         ; add data
    add   r2,#sizeof (n)  ; xptrL + 2
    addc  r3,#0x00        ; xptrH + 1 + Cy
    sub   n,#1
    jmp   cc_nz,lM        ; loop if not eot
    ret                   ; return result in R4
  }
stop:
  return (0);
}

This example generates the following code:

             ; FUNCTION XpAddUp (BEGIN  RMASK = @0x4010)
;---- Variable 'pTab' assigned to Register 'R9/R10' ----
;---- Variable 'n' assigned to Register 'R8' ----

004E F029          mov   r2,word0 pTab   ; get SOF part of xhuge ptr
0050 F03A          mov   r3,word2 pTab   ; get SEG part of xhuge ptr
0052 4880          cmp   n,#0            ; count zero ?
0054 BD08          jmp   cc_sle,stop     ; stop if so.
0056 E004          mov   r4,#0x0000      ; clear result
0058         lM:
0058 DC03          lM: exts  r3,#1
005A 084A          add   r4,[r2]         ; add data
005C 0822          add   r2,#sizeof (n)  ; xptrL + 2
005E 1830          addc  r3,#0x00        ; xptrH + 1 + Cy
0060 2881          sub   n,#1
0062 3DFA          jmp   cc_nz,lM        ; loop if not eot
0064 CB00          ret                   ; need result in R4
0066         stop:
0066 E004          MOV   R4,#00H
0068 CB00          RET
             ; FUNCTION XpAddUp (END    RMASK = @0x4010)
  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.