Repeat directives

There may be a need to repeat the same portion of code with minor differences or even without them. Assemblers have directives (sometimes referred to as built-in macro instructions) that allow us exactly this. There are three such statements common to all three assemblers--FASM, MASM and GAS:

  • rept count: The rept directive followed by the count parameter simply makes count copies of the code defined in the block. In case of Flat Assembler, we may declare the second parameter, which will equal the number of the current iteration (1 based). For example, the following code:
hex_chars:
rept 10 cnt {db '0' + cnt - 1}
rept 6 cnt {db 'A' + cnt - 1}

This would generate an array of hexadecimal characters named hex_chars, and is equivalent to:

hex_chars db "0123456789ABCDEF"
  • irp arg, a, b, c, ...: The irp directive is followed by an argument and a list of parameters. The argument (here arg) represents a single parameter during each iteration. For example, this code:
irp reg, eax, ebx, ecx {inc reg}

Sequentially increments registers EAX, EBX then ECX.

  • irps arg, a b c ...: The irps directive is the same as irp, except that parameters in the list are not separated with commas.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset