IRPC Directive 

The IRPC (iteration repeat with character substitution) directive is similar to the IRP directive. The difference is in how the variable parameter values are specified. Its syntax is

     IRPC parameter, string
       statments
     ENDM
The statements in the macro body are repeated once for each character in string. Like in the IRP directive, string specifies the number of iterations as well as the character to be used in each iteration.

Example: Write a macro to display a string in upper case.
  DSTRU  MACRO  string
           MOV AH, 2 
           IRPC char, < string >
             LOCAL DISP
                 MOV DL, "&char"
                 CMP DL, "Z"
                 JB  DISP
                 CMP DL, "a"
                 JB  DISP
                 CMP DL, "z"
                 JA  DISP
                 SUB DL, 20H
           DISP: INT 21H
           ENDM
         ENDM
 

Note that the angle brackets around the string argument in the IRPC macro are needed to allow for spaces in the string. Also, it is important to note here that the LOCAL definition has to be in the IRPC macro body and not in the DSTRU macro body.

The macro invocation DSTRU Hello will produce the macro expansion as shown in the next figure.

Expansion of the macro invocation DSTRU Hello
             dstru Hello
   1            MOV AH, 2
   2            MOV DL, "H"
   2            CMP DL, "Z"
   2            JB  ??0000
   2            CMP DL, "a"
   2            JB  ??0000
   2            CMP DL, "z"
   2            JA  ??0000
   2            SUB DL, 20H
   2    ??0000: INT 21H
   2            MOV DL, "e"
   2            CMP DL, "Z"
   2            JB  ??0001
   2            CMP DL, "a"
   2            JB  ??0001
   2            CMP DL, "z"
   2            JA  ??0001
   2            SUB DL, 20H
   2    ??0001: INT 21H
   2            MOV DL, "l"
   2            CMP DL, "Z"
   2            JB  ??0002
   2            CMP DL, "a"
   2            JB  ??0002
   2            CMP DL, "z"
   2            JA  ??0002
   2            SUB DL, 20H
   2    ??0002: INT 21H
   2            MOV DL, "l"
   2            CMP DL, "Z"
   2            JB  ??0003
   2            CMP DL, "a"
   2            JB  ??0003
   2            CMP DL, "z"
   2            JA  ??0003
   2            SUB DL, 20H
   2    ??0003: INT 21H     
   2            MOV DL, "o"
   2            CMP DL, "Z"
   2            JB  ??0004
   2            CMP DL, "a"
   2            JB  ??0004
   2            CMP DL, "z"
   2            JA  ??0004
   2            SUB DL, 20H
   2    ??0004: INT 21H