tags:

views:

76

answers:

1

Hi everyone,

I would like to dynamically create a set of labels in an assembly function using a gas macro. I would like to do something like this:

 .macro set_up_jumptab_entry prefix, from=0, to=10
     .quad \prefix_\item
     .if \to-\from
     set_up_jumptab_entry \prefix,"(\from+1)",\to
     .endif
 .endm
 set_up_jumptab_entry myfunc 0 10

Here \prefix_\item would be something like myfunction_7. Now, I can find lots of examples of recursive invocation, but I haven't found one of just label concatenation involving passed-in macro arguments. Gas is quite poorly documented, so answering this question is difficult for me.

  1. Can you concatenate arguments to macros with other tokens to make single tokens?
  2. What's your favorite gas assembler reference?
+1  A: 

things like

\argA\()\argB :

should create a label composed by argA and argB.

EDIT

Testing, \() seems to be not necessary; the test code was:

    .file   "test.c"

.macro prova argA, argB
\argA\argB :
 .endm
    .text
.globl main
    .type   main, @function
main:
    leal    4(%esp), %ecx
    andl    $-16, %esp
    pushl   -4(%ecx)
    pushl   %ebp
    movl    %esp, %ebp
    pushl   %ecx
    movl    $0, %eax
    popl    %ecx
    popl    %ebp
    leal    -4(%ecx), %esp
        prova abc, def
        jmp  abcdef
    ret
    .size   main, .-main
    .ident  "GCC: (GNU) 4.3.2"
    .section    .note.GNU-stack,"",@progbits

which is just gcc -S test.c output (lazyness:D) of a minimal C code. (prova means test in italian)

ShinTakezou
of course it will loop forever, so don't execute the final code!
ShinTakezou