| ||||||||||||||||||||||
| ||||||||||||||||||||||
The REPT directive can be used to repeat a block of statements. Its syntax is REPT expression statments ENDMWhen 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.
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 100Invocation 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
To declare a word array B of the first 5 factorials, the data segment can contain B LABEL WORD FACT 5which will be expanded to B DW 1 DW 2 DW 6 DW 24 DW 120 |