Keil Logo

% Operator

The percent operator ('%') is used to pass the value of an expression to a macro rather than passing the literal expression itself. The following example shows a macro definition that requires a numeric value along with macro invocations that use the percent operator to pass the value of an expression to the macro.

OUTPORT MACRO   N
        MOV     R1, #N
        ENDM

RESET_SIG EQU 0FFh
CLEAR_SIG EQU 0

OUTPORT %(RESET_SIG AND NOT 11110000b)
; Expands into MOV R1, #15

OUTPORT %(CLEAR_SIG OR 11110000b)
; Expands into MOV R1, #240

The expressions evaluated in the highlighted lines could not be passed to the macro because the macro expects a numeric value. Expressions like these must be evaluated before the macro. The percent operator forces the assembler to generate a numeric value which is then passed to the macro.

  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.