17 if — conditional assembly, If — conditional assembly – Motorola HC12 User Manual

Page 182

Advertising
background image

User’s Manual

MCUez HC12 Assembler

182

Assembler Directives

MOTOROLA

Assembler Directives

8.17 IF — Conditional Assembly

Syntax:

IF

<condition>

[<assembly language statements>]

[

ELSE

]

[<assembly language statements>]

ENDIF

Description:

If <condition> is true, the statements immediately following
the

IF

directive generate code. Assembly continues until the

corresponding

ELSE

or

ENDIF

directive is reached. Then all

statements until the corresponding

ENDIF

directive are

ignored. Nesting of conditional blocks is allowed. The
maximum level of nesting is limited by available memory at
assembly time.

The expected syntax for <condition> is:

<condition> := <expression> <relation> <expression>

<relation> :=

"=" | "!=" | " >=" | ">" | "<=" | "<" | "<>"

The <expression> must be absolute. It must be known at
assembly time.

Example:

This is an example of using conditional assembly directives:

Try: EQU 0
IF Try != 0
LDD #1023
ELSE
LDD #0
ENDIF

The value of

TRY

determines the instruction that generates

code. As shown, the

LDD #0

instruction generates code.

Changing the operand of the

EQU

directive to one causes the

LDD #1023

instruction to generate code instead.

This is the listing provided by the assembler for these lines of code:

0000 0000 Try: EQU 0

0000 0000 IF Try != 0

ELSE

000000 CC 0000 LDD #0

ENDIF

Advertising