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.
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With