The syntax of the IF
The IF directive assembles the then part if the expression evalues to true (nonzero). and IFE
The IFE directive assembles the then part if the expression is false (zero). directives is
IF expression
IFE expression
The IF directive assembles the then part if the expression
evalues to true (nonzero). The IFE directive is the IF
counterpart and assembles the then part if the expression is
false (zero).
The next table shows some operators that can be used in
an expression.
Operator Type | Operators
|
Arithmetic | +,-,*,/,mod,unary + and -
|
Relational | EQ, GE, GT, LE, LT, NE
|
Logical | NOT, AND, OR, XOR
|
Example: Write a macro to define a block
of memory words with N entries, consisting of the
first K integers, followed by N-K zero words. |
BLOCK MACRO N, K
I=1
REPT N
IF K+1-I
DW I
I=I+1
ELSE
DW 0
ENDIF
ENDM
ENDM
| | | | | | | | | | |
The following macro invocation
A LABEL WORD
BLOCK 10, 5
will produce the following statements
A DW 1
DW 2
DW 3
DW 4
DW 5
DW 0
DW 0
DW 0
DW 0
DW 0
Example: Write a macro to exchange two memory
operands such that the two operands can be either byte
or word operands. |
MXCHG MACRO operand1, operand2
IF (TYPE operand1) NE (TYPE operand2)
%OUT Operands of MXCHG do not match.
ELSE
IF (TYPE operand1) EQ 1 ; BYTE operands
XCHG AL, operand1
XCHG AL, operand2
XCHG AL, operand1
ELSE ; WORD operands
XCHG AX, operand1
XCHG AX, operand2
XCHG AX, operand1
ENDIF
ENDIF
ENDM
| | | | | | | | | | | | | | |
The TYPE
The TYPE operator returns the number of bytes reserved for the operand in memory. operator returns the number of bytes
reserved for the operand in memory. The next table shows the values
returned by the type operator.
Type of Memory Operand | Value Returned
|
BYTE | 1
|
WORD | 2
|
DWORD | 4
|
QWORD | 8
|
NEAR | FFFFH
|
FAR | FFFEH
|
Constant | 0
|
The %OUT
The %OUT directive is used for displaying text on the screen. directive is used for displaying text on
the screen. It syntax is
%OUT text
where
text can contain any character. This directive is useful for
displaying error or warning messages during the assembly process.