REPT Directive 

The REPT directive can be used to repeat a block of statements. Its syntax is

     REPT  expression
       statments
     ENDM
When the assembler encounters this macro, the statements in the macro body are repeated a number of times equivalent to the value of the expression. It is important to note that expression must evaluate to a constant at assembly time.

 REPT Macro Invocation

Example: Write a macro to initialize a block of memory to the first N integers.
   BLOCK  MACRO  N  
            K=1
            REPT N
              DW K
              K=K+1
            ENDM
          ENDM
 

To declare a word array A and initialize it to the first 100 integers, we can place the following statements in the data segment:

     A LABEL WORD
       BLOCK 100
Invocation of the BLOCK macro initializes K to 1 and the statements inside the REPT macro are assembled 100 times. The first time, DW 1 is generated and K is incremented to 2; the second time, DW 2 is generated and K becomes 3; .... the 100th time, DW 100 is generated and K becomes 101. The final result is equivalent to
     A  DW    1
        DW    2
        DW    3
        .
        .
        .
        DW    100

Example: Write a macro to initialize an n-word array to 1!, 2!, ..., n!.
   FACT   MACRO  N  
            M=1
            F=1
            REPT N
              DW F
              M=M+1
              F=M*F
            ENDM
          ENDM
 

To declare a word array B of the first 5 factorials, the data segment can contain

     B  LABEL  WORD
        FACT   5
which will be expanded to
     B  DW    1
        DW    2
        DW    6
        DW    24
        DW    120