Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm porting some code over to Linux (well, building it on Linux anyway) and I've hit a problem.

In VS you mark out some inline asm like this:

__asm
{
  mov eax, something
}


but for G++ it would need:

asm (
  "mov eax, something"
);


Neither compiler seems to be able to use the other syntax, is there anything I can do to avoid having duplicate copies with slightly different syntax?

Note: I'm also aware of the Intel / AT&T syntax differences, which I can already set options for.
Posted
Updated 28-Feb-12 19:23pm
v2
Comments
Sergey Alexandrovich Kryukov 28-Feb-12 21:43pm    
Is it a question? This is what it is, nothing else.
--SA
Maximilien 28-Feb-12 22:33pm    
AFAIK, assembly is the least portable code ever.

1 solution

something as crusty as ...

// ASM abstracting header
#ifdef GPLUSPLUS

#define BEGIN_INLINE_ASM asm{
#define END_INLINE_ASM };
#define MNEM2(a,b) "a,b"

#endif

#ifdef VSTUDIO

#define BEGIN_INLINE_ASM __asm{
#define END_INLINE_ASM }
#define MNEM2(a,b) a,b

#endif


then in your 'code'

BEGIN_INLINE_ASM 
MNEM(mov eax,something)
END_INLINE_ASM 

.. maybe?

Failing that, have the asm in files of another extension, and a parser that sorts them out into 'c', and build rule that runs that parser before the compiler?

Really depends how much code you're in-lining
 
Share this answer
 
Comments
Anthony Mushrow 29-Feb-12 5:03am    
I was hoping to avoid making some defines for it, at least there's not too much around so making them all use the defines shouldn't take too long.

Looking at the brighter side if I ever need to support any different syntax I can just make a new define.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900