Ax51 User's Guide

IF Function

The IF MPL function evaluates a logical expression and, based on the result, expands or skips its text arguments. The syntax for the IF function is:

%IF (expression) THEN (balanced-text1) <[>ELSE (balanced-text2)<]> FI

The IF function first evaluates the expression. If it is TRUE, balanced-text1 is expanded. If it is FALSE and the optional ELSE clause is included, balanced-text2 is expanded. If the expression is FALSE and the ELSE clause is not included, the IF function returns a null string. The FI keyword terminates the IF function.

When IF functions are nested, the ELSE clause refers to the most recent IF that is open (FI has not terminated the IF). FI terminates the most recent IF that is open.

Source Text

%*DEFINE (ADDSUB (op,p1,p2)) (
  %IF (%EQS (%op,ADD)) THEN (
    ADD  %p1,%p2
  ) ELSE (%IF (%EQS (%op,SUB)) THEN (
    SUB  %p1,%p2
     ) FI
  ) FI
)

%ADDSUB (ADD,R15,R3)  %' generate ADD R15,R3'
%ADDSUB (SUB,R15,R9)  %' generate SUB R15,R9'
%ADDSUB (MUL,R15,R4)  %' generates nothing !'

Output Text

ADD    R15,R3
SUB    R15,R9