Summary: Repeat loops are expanded at assembly time.
The REPEAT directive is the simplest loop directive. It specifies the number of times to generate the statements inside the macro. The syntax is
REPEAT constexpr
statements
ENDM
The constexpr can be a constant or a constant expression, and must contain no forward references. Since the repeat block will be expanded at assembly time, the number of iterations must be known then.
Here is an example of a repeat block used to generate data. It initializes an array containing sequential ASCII values for all uppercase letters.
alpha LABEL BYTE ; Name the data generated
letter = 'A' ; Initialize counter
REPEAT 26 ;; Repeat for each letter
BYTE letter ;; Allocate ASCII code for letter
letter = letter + 1 ;; Increment counter
ENDM
Here is another use of REPEAT, this time inside a macro:
beep MACRO iter:=<3>
mov ah, 2 ;; Character output function
mov dl, 7 ;; Bell character
REPEAT iter ;; Repeat number specified by macro
int 21h ;; Call DOS
ENDM
ENDM