Conditional assembly

The conditional assembly mechanism of the assembler 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:

For example, in the following code, the C preprocessor replaces y with x+1 at the point at which y is used. This becomes 2+1 because the value of x at that point is 2. Therefore, example() returns 0.

#define x 1
#define y x+1
#define x 2

int example()
{
#if y == 2
    return 1;
#else
    return 0;
#endif
}

Conditional assembly is based on variables, and works on each line in turn. Unlike the C preprocessor, the assembler evaluates expressions. It does this for a directive at the point at which the directive occurs. Conditional assembly is controlled by the following:

For example, in the following code, the assembler evaluates x+1 at the point at which the SETA directive occurs. Because the value of x at that point is 1, y is set to 2. Therefore, the MOV instruction 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
    ELSE
        MOV     r0, #0
    ENDIF

    END

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0473H
Non-ConfidentialID070912