The syntax of the IFB
The IFB directive assembles the then part if the argument is blank. and IFNB
The IFNB directive assembles the then part if the argument is not blank. directives is
IFB < argument >
IFNB < argument >
Note that the angle brackets are required.
The IFB directive assembles the then part if the argument
is blank. The IFNB directive assembles if the argument is
not blank.
These directives are useful to test the presence as well
as the number of arguments specified in a macro call.
Example: Write a macro READ MACRO BUF, LEN
that either reads a string
into the byte array BUF of length LEN (if both arguments are
present), or reads a single
character into AL (if both arguments are missing). |
READ MACRO BUF, LEN
; BUF = STRING BUFFER ADDRESS
; LEN = MAX NO. OF CHARS TO READ
IFNB < BUF >
IFNB < LEN >
MOV AH, 0AH ; read string function
LEA DX, BUF ; DX has string address
MOV BUF, LEN ; 1st byte has array size
INT 21H ; read string
ELSE
%OUT ERROR: Missing 2nd argument
EXITM
ENDIF
ELSE
MOV AH, 1 ; read character function
INT 21H ; read character
ENDIF
ENDM
| | | | | | | | | | | | | | | | | |
If the above macro is invoked by the statement
READ MSG, 10
then since both arguments are present, the following code will
be assembled
MOV AH, 0AH
LEA DX, MSG
MOV MSG, 10
INT 21H
 String MSG Declaration |
String MSG must be a declared array of at least 13 bytes
(1 byte for the maximum number of characters expected,
1 byte for the actual number of characters read,
10 bytes for storing the characters, and 1 byte for
the carriage return.)
|
If the macro invocation is
READ
then since both arguments are blank, the following code will
be assembled
MOV AH, 1
INT 21H
If the macro is improperly called with only one argument,
then an error message is displayed using the %OUT
directive and the macro expansion
process is terminated using the EXITM
The EXITM directive stops any macro expansion or repeat block expansion that is in progress. All remaining statements after EXITM are ignored.
directive.
The EXITM directive stops any macro expansion or repeat block
expansion that is in progress. All remaining statements
after EXITM are ignored.
Another way for indicating when a macro is invoked incorrectly
is by using the .ERR
When the assembler encounters the .ERR directive, it displayes the message "forced error", which indicates a fatal assembly error. directive. When the assembler
encounters this directive, it displayes the message
"forced error", which indicates a fatal assembly error.