3

Is there a way to have the GNU assembly process a source file that contains macros, expand them, and then output the expanded equivalent code in a form that could be assembled by as? Basically, I'm looking for something that's an equivalent of gcc's -E argument.

I have found the -a -am options (as per this question here) but it doesn't output code in a form that can be assembled, but rather outputs the process of expanding the macros in a heavily annotated fashion. The expanded code is mixed in with a lot of other stuff. It might be possible to parse that output and get what I want, but I'm hoping there's a way to get it to just output the expanded assembly code that it would actually turn into machine code.

(In case it matters, I am cross-compiling to m68k, so I'm limited to tools that can work with that.)

6
  • Does gcc -x assembler-with-cpp -S do what you want? Commented Jun 11 at 17:51
  • 2
    I am not aware of such a feature. Commented Jun 11 at 17:51
  • 1
    You could assemble then disassemble the machine code back into asm source. For x86, Agner Fog's objconv can disassemble into source that's ready to be assembled. But you'd lose stuff like .p2align directives, and of course comments. Depends on the use-case whether that's useful. Commented Jun 11 at 18:10
  • @PeterCordes I did come across that, but in my case I'm working with m68k assembly, and I believe that tool is x86/x86_64 only. (I've updated my question to mention this in case it comes up again.) Commented Jun 11 at 19:43
  • 1
    There are probably other disassemblers, or ways to process the output from objdump -drw. For example How to disassemble a binary executable in Linux to get the assembly code? uses a sed command on the output of llvm-objdump 'foo.o' --no-show-raw-insn --no-leading-addr -d -C --symbolize-operands -j.text (With -Mintel since they're using x86 with Intel syntax, but hopefully the sed command would only need minor changes for the characters that can appear in m68k syntax.) Commented Jun 11 at 20:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.