Search code examples
assemblymacrosgnu-assembler

How to create a GNU GAS macro that expands to an expression like "(x+y*240)*2"?


I'm building a program for ARM Linux using GAS, but I want to do some macros to make my development some more smart. Then I want to know:

How could I do a macro for this: (x+y*240)*2, were x and y are int, that will be used like this:

mov r0, MACRO_SHOULD_BE_CALLED_HERE

And how could I do a macro that should be called like this:

JUST_MACRO_CALLED_HERE_TO_DO_SOMETHING

That will just do something that is already defined inside it, like a print function for example.

Also, if I need some arguments on the macro or a function call. How I could do it?

PS: r0 is an ARM register, like eax of x86


Solution

  • GAS vs NASM comparison - Macros shows ways of doing parametrized macros, but it's simple substitutions.