tags:

views:

176

answers:

2

Hi

And again I ran into a problem where I cant find a straightforward solution...

I am doing some inline assembly and I wanna execute some code a few times by using the .rept directive which tells the assembler to act as if the lines following .rept, up to the one just before .endr, are repeated the specified number of times.

The obvious problem is of course that the label 18 has already been specified. I wonder if there is a way to generate some 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" );
A: 

If you don't mind doing some of the work by hand, this should be doable by using the built-in . (dot) symbol, which evaluates to the current target address. See the documentation. You should be able to do something like:

asm volatile("jne .+1");

Where the 1 needs to be changed according to how far away you want to jump, of course. This is the by-hand part, since you'll need the offset in bytes. I haven't tested this, but I imagine it should work.

This page in the documentation also shows how to use string substitution to generate labels, you might be able to use that technique, too.

unwind
+1  A: 

why not skip the .rept and .endr and just loop instead? set ecx to 10 (or 0A if you want 10 loops, not 16) put a label (say, loopbegin:) where your rept statement is, and loop loopbegin) where the .endr statement is. That way your 18 label won't be ambiguous.

Carson Myers