Page 1 of 1

How to replace a number of instructions with my macros?

Posted: Mon Oct 11, 2010 6:12 am
by limp
Hi all,

I would like to redirect a number of instructions to my own functions.
For doing that, I created a header file which defines a macro for any instruction I want to replace like that:

Code: Select all

#define cli() __asm__ ("nop":::"memory")
...
Now, if I include my header file and write an inline assembly code like that:

Code: Select all

asm("cli");
I want the assembler to replace cli call with a call to my cli().

Is it possible to achieve something like that or I should explicitly call my functions from the inline assembly code?

Thank you very much for your time.

Re: How to replace a number of instructions with my macros?

Posted: Mon Oct 11, 2010 6:30 am
by JamesM
Hi,

String constants are not preprocessed, so you'll have to call the function yourself.

I honestly think you're going about it wrong though.

James

Re: How to replace a number of instructions with my macros?

Posted: Mon Oct 11, 2010 9:28 am
by qw

Code: Select all

#define cli() __asm__ __volatile__ ("cli")
#define nop() __asm__ __volatile__ ("nop")

#if SOMETHING
# define conditional_cli() cli()
#else
# define conditional_cli() nop()
#endif
Please, don't name a function after something it does not do.

Re: How to replace a number of instructions with my macros?

Posted: Mon Oct 11, 2010 9:35 am
by fronty
You could also compile the source file to assembly, run it through cpp or m4 or something which replaces the instructions and then assemble it. gcc can do this nicely with .S extension and -D option. It is suitable for instructions that doesn't take parameters, for other instructions just awk it or use perl.