6.14 Conditional assembly

Conditional assembly works differently from conditional compilation using the C preprocessor.

The C preprocessor performs textual transformations of macro identifiers into their definitions. Transformation occurs at the point at which the identifier is used. The C preprocessor is controlled by the following:
  • Preprocessor directives embedded in the C source file, for example, #define.
  • Compiler command-line options, for example -D and -U. These have the same effect as a #define or #undef directive at the beginning of each source file.
For example, in the following code, the C preprocessor replaces y with x+1 at the point at which y is used, and therefore example() returns 0:
#define x 1
#define y x+1
#define x 2
int example()
#if y == 2
    return 1;
    return 0;
Conditional assembly is based on variables, and works on each line in turn. Unlike the C preprocessor, the assembler evaluates expressions. Conditional assembly is controlled by the following:
  • Assembler directives that declare and set the value of variables, for example GBLx, LCLx and SETx.
  • Assembler directives that control the flow of the assembly, for example WHILE, IF and ELSE.
  • Assembler directives that define macros, for example MACRO.
  • The assembler command-line option --predefine, which pre-executes a GBLx and SETx directive.
For example, in the following code, the assembler evaluates x+1 at the point at which the SETA directive occurs, and therefore MOV sets r0 to 1:
    GBLA    x
    GBLA    y
x   SETA    1
y   SETA    x+1
x   SETA    2
    AREA    example, CODE
    IF y == 2
        MOV     r0, #1
        MOV     r0, #0
Related reference
12.2 About assembly control directives
9.57 --predefine "directive"
Related information
-Dname[(parm-list)][=def] compiler option
-Uname compiler option
Non-ConfidentialPDF file icon PDF versionARM DUI0379G
Copyright © 2007, 2008, 2011, 2012, 2014, 2015 ARM. All rights reserved.