Dynamic labels in x86 assembler
And again I ran into a problem where I cannot find a direct solution ...
I'm doing some inline assembly, and I want to execute the code multiple times using the .rept directive, which tells the assembler to act as if the lines following the .rept, all the way back to before .endr, are repeated a specified number of times.
The obvious problem, of course, is that label 18 has already been specified. wondering if there is a way to create a dynamic label for each iteration?
__asm__ __volatile__ (".rept 10 \n\t");
__asm__ __volatile__( "test eax, eax \n\t" );
__asm__ __volatile__( "jne 18f\n\t" );
...
__asm__ __volatile__( "18: nop 18f\n\t" );
__asm__ __volatile__( ".endr\n\t" );
If you don't mind doing some manual work, this should be done with an inline character .
(dot) that evaluates to the current target address. See the documentation . You should be able to do something like:
asm volatile("jne .+1");
Where 1
you need to change depending on how far you want to jump, of course. This is a side part as you will need the byte offset. I haven't tested this, but I think it should work.
This documentation page also shows how to use string substitution to generate labels, you can also use this technique.
a source to share