How to replace a number of instructions with my macros?

Programming, for all ages and all languages.
Post Reply
limp
Member
Member
Posts: 90
Joined: Fri Jun 12, 2009 7:18 am

How to replace a number of instructions with my macros?

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

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

Post 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.
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

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

Post 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.
Post Reply