Label in% rep section in NASM

I have a preprocessor directive %repthat creates a preprocessor loop. I would like to declare a shortcut in it, possibly with some concatenation, but I cannot get the syntax correctly.

%assign i 0 
%rep    64 
   label_%i: ;this, of course, doesn't work
      inc rax    
%assign i i+1 
%endrep

So, how to get the NASM preprocessor to generate label_ifor each "iteration"?

+4
source share
2 answers

This can be done using notation %+. Here is an excerpt from the documentation:

4.1.4 Combining Single-Line Macros:% +

, . , , .

, % + , % + 1, .

.

+2

%rep, %%label :

%macro  jmpfwd 0
    times 21 nop
    jmp %%fwd                  ;;;;;   <<<------ This jump
    add ax, 0x1234    ; can this stall decoding?
;    lea eax, [ebx+edx+1]
  align 64
  %%fwd:                       ;;;;;   <<<------ jumps here
%endmacro

%rep

    .looptop:
%rep 4
    jmpfwd
%endrep
; times 4 jmpfwd   nope, TIMES only works on (pseudo)instructions, not macros

    dec ecx
    jnz .looptop

(, Skylake LCP- , LCP-, add , jmp jmp. times 21 nop -.)

0

Source: https://habr.com/ru/post/1625747/


All Articles