How to concatenate GNU GAS macro arguments with other tokens to make single label?

StackOverflow https://stackoverflow.com/questions/2990413

  •  24-10-2019
  •  | 
  •  

Pergunta

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?
Foi útil?

Solução

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)

Outras dicas

What's your favorite gas assembler reference?

The docs cover this one quite well https://sourceware.org/binutils/docs/as/Macro.html

The string `()' can be used to separate the end of a macro argument from the following text. eg:

.macro opcode base length
    \base\().\length
.endm
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top