0

I got a tricky situation. I got a project with an .asm file that do some logic. I got a macro #defineed in a different .h file in the project.

Is it possible to use the macro in the .asm file?

What I tried so far is this in the header file

#define MOVRAX "mov rax, rcx"

and then something like this in the asm:

PUBLIC test_fn

.CODE
     
test_fn PROC
    MOVRAX
test_fn ENDP

END

which sadly doesnt compile... is there any way to do that?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Daniel Cohen
  • 163
  • 1
  • 7
  • https://stackoverflow.com/a/6166544/5910058 – Jesper Juhl Aug 22 '20 at 13:58
  • 1
    that is not remotely what I asked about. I already got a working `asm` file - which is not inline. I want to use macros in that file. – Daniel Cohen Aug 22 '20 at 15:16
  • It wasn't an answer. Just a comment with a reference I thought might be useful to you. If it's not; just ignore it. – Jesper Juhl Aug 22 '20 at 15:22
  • 1
    Does the macro need to be a C macro for some reason? Also the quotes in the macro expansion would result in illegal assembly syntax, so are they necessary for some reason? – Ross Ridge Aug 22 '20 at 16:05
  • no, the macro should be just `mov rax, rcx`, it was a typo on my side – Daniel Cohen Aug 22 '20 at 16:13
  • This has nothing to do with C++. – n. m. could be an AI Aug 22 '20 at 17:47
  • 2
    I'm not following the requirement here. Why would you have `mov rax, rcx` in a c++ macro? It obviously can't ever be used in c++ code? masm has [macros](https://learn.microsoft.com/en-us/cpp/assembler/masm/macro?view=vs-2019). Perhaps you could put your macro in a file specifically intended for asm, then have your asm files [include](https://learn.microsoft.com/en-us/cpp/assembler/masm/include-masm?view=vs-2019) it? Failing that, I suppose you could try to manually invoke the c++ preprocessor against an asm file. Seems risky though. – David Wohlferd Aug 22 '20 at 20:14
  • Why would you expect that to compiler? It doesn't contain a `#include "foo.h"` line so even if you did set up your build to run that file through the C preprocessor before assembling (like GCC will with `.S` files), it won't have the macro defined. Unless you define it on the command line like `cc -E "-DMOVRAX=mov rax, rcx" foo.asm` – Peter Cordes Aug 22 '20 at 20:40

0 Answers0