Share definitions between C and ASM?

Other misc things
Post Reply
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Share definitions between C and ASM?

Post by DarkSchneider »

I have seen that the assembler uses the #define as in C, but I have the problem that for checking if already defined seems not to be the same, for C in the H file is with #ifndef/#define/#endif and for ASM is ifndef/#define/endif, notice that for ASM the check block does not uses the # prefix.

So how can I create a single file of definitions to get included by both C and ASM?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: Share definitions between C and ASM?

Post by dom »

I think that the easiest solution is wrap the assembler in a C file:

Code: Select all

static void wrapper() __naked
{
__asm
    SECTION ...
    PUBLIC ...

__endasm;
}
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: Share definitions between C and ASM?

Post by DarkSchneider »

Probably, but I like to have the ASM in its own file with its format then assemble.
Currently what I do is duplicate those definitions, and when I am going to change one, "grep" for that definition in all sources and change in both if required.
If I'd do it frequently, then a bash script for changing definitions in all files it appears could make the trick, but is not so often to do it.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: Share definitions between C and ASM?

Post by dom »

Paulo just pushed a change which supports #ifdef etc in the assembler, so that will be in tonights build
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: Share definitions between C and ASM?

Post by DarkSchneider »

Nice!
Post Reply