Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU as .macro directive expansion

Is there a way to have GNU as only expand .macro directives in a .S file, producing another .S file without them? Similiar to what gcc -E does with C code.

Note this is about the assembler .macro directive like in the following code, not about C-style #define macros which can be expanded via cpp.

.macro my_macro src, so, dest
    movl    \so+10(\src), %r8d
like image 777
Jürgen Strobel Avatar asked Jan 30 '12 13:01

Jürgen Strobel


People also ask

What are assembler directives and macros?

The assembler directives are used to tell the assembler to do something. For instance: Defining a symbol, change sections, repeat code, change the location counter, etc. The . macro directive defines the start of a new macro, the name of the macro and the macro arguments.

Is ENDM a macro directive?

This directive terminates expansion of a macro body and passes control to the nearest . ENDM. Write this directive in the body of a macro definition. This directive declares that the label specified as an operand is a macro local label.

What are the assembler directives?

Directives are instructions used by the assembler to help automate the assembly process and to improve program readability. Examples of common assembler directives are ORG (origin), EQU (equate), and DS. B (define space for a byte).

How do I run a GCC preprocessor?

The -E option causes gcc to run the preprocessor, display the expanded output, and then exit without compiling the resulting source code. The value of the macro TEST is substituted directly into the output, producing the sequence of characters const char str[] = "Hello, World!" ; .


1 Answers

GNU as's preprocessor doesn't handle .include and .macro, as everything starting with a dot is in fact an assembler directive; thus, macro expansion is performed along program assembly, and cannot be done separately, at least by as.

You have these options:

  • Search google for someone else's script
  • Write your own (seems a nice programming exercise)
  • Switch to C-style macros or M4

C-style macro processing is performed by default when you use the .S (capital s) extension for assembly files you use to feed gas, and the C preprocessor can be also invoked standalone with command cpp

like image 89
AquilaIrreale Avatar answered Oct 19 '22 20:10

AquilaIrreale