views:

39

answers:

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

+1  A: 

I've never seen an assembler that supported macros like you want for your first example. The second example is pretty straightforward though - even the most basic assembler documentation should cover it. For GNU as, you probably want something like:

.macro JUST_MACRO_CALLED_HERE_TO_DO_SOMETHING
    ...
.endm

Put whatever instructions you want in place of the ....

Be careful with assembler macros that you don't stomp on a bunch of registers that you were using to hold important data. Usually a function call is a better way to solve these problems.

Carl Norum
But if I need some arguments on the macro or a function call. How I could do it?
Nathan Campos
@Nathan, maybe you should read the documentation.
Carl Norum
@Carl: This is what I'm doing right now. **;)**
Nathan Campos
+1  A: 

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

Joe