This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Include macro in .s file

Hi,

I am using arm cortex m4 and I wrote an assembly code(in .S file). There is one macro which is defined in other file(.h file). I want to use that macro in my assembly code, so that I can enable/disable certain lines of instructions like we do in C code (using #ifdef).

Kindly help me to do this .

  • Hi there, I have moved your question to the Architectures and Processors forum. Many thanks.

  • That should work by default, assuming that the macro expands to something that is valid asm code, and the .h file is set up not to produce illegal asm code via #if !(defined(__ASSEMBLER__) || defined(__IAR_SYSTEMS_ASM__)) or similar.

    Note that gcc will invoke the C pre-processor only if the file extension is a CAPITAL "S", a lowercase "s" is assumed to not want the preprocessor.

    With CMSIS and "modern best C practices", a lot of pre-processor stuff uses struct, union, typedef and enum instead of #define, which makes the definitions unusable in asm files.

    At one point, I did some work on "minimal" ARM development (assembler only) for STM32, which included conversion of ST's .h include files to gnu assembler .inc files, which I did semi-automatically using some EMACS macros.  You can see those macros and the results here: https://github.com/WestfW/Minimal-ARM/blob/master/inc/stm32f103c8.asmh#L6089  (the rest of the repository and wiki might be interesting too, though it's pretty much been left in an "unfinished" state for the last 8 years.)