Conditional assembly directives
Syntax
ELSE
ELSEIF condition
ENDIF
IF condition
Parameters
| One of these: | |
An absolute expression | The expression must not contain forward or external references, and any non-zero value is considered as true. | |
| The condition is true if | |
| The condition is true if |
Description
Use the IF, ELSE, ELSEIF, and ENDIF directives to control the assembly process at assembly time. If the condition following the IF directive is not true, the subsequent instructions do not generate any code (that is, it is not assembled or syntax checked) until an ELSEIF condition is true or ELSE or ENDIF directive is found.
Use ELSEIF to introduce a new condition after an IF directive. Conditional assembly directives can be used anywhere in an assembly, but have their greatest use in conjunction with macro processing.
All assembler directives (except for END) as well as the inclusion of files can be disabled by the conditional directives. Each IF directive must be terminated by an ENDIF directive. The ELSE and ENDIF directives are optional, and if used, must be inside an IF...ENDIF block. IF...ENDIF and IF...ELSE...ENDIF blocks can be nested to any level.
Example
This example uses a macro to add a constant to a direct page memory location:
addMem macro loc,val ; loc is a direct page memory
; location, and val is an
; 32-bit value to add to that
; location.
if val = 0
; Do nothing.
elseif val < 16
mov.l #loc,R1
mov.l [R1],R2
add #val,R2
mov.l R2,[R1]
else
mov.l #loc,R1
mov.l [R1],R2
add #val,R2,R2
mov.l R2,[R1]
endif
endm
module addWithMacro
section CODE:CODE
code
addSome addMem 0xa0,0 ; Add 0 to memory loc. 0xa0
addMem 0xa0,1 ; Add 1 to the same address
addMem 0xa0,2 ; Add 2 to the same address
addMem 0xa0,3 ; Add 3 to the same address
addMem 0xa0,47 ; Add 47 to the same address
rts
end