0
votes

For inline asm code I use __asm for vc++ compiler and __asm__() or asm() construct for gcc under linux. (intel/at&t syntax accordingly)

Is there a way to declare inline assembly (x86) in C for them both in a universal way?

P.S. An automated tool for incorporating both is also acceptable.

2
Assembler in source file has always been a compiler specific extension. - Some programmer dude
The simple answer is no. A solution would be to put the assembly code in a macro and #ifdef it for each platform. - Neil
At that point it becomes easier to use YASM and link the asm code in separately. It wouldn't be inline, but it would work with GCC, MSVC, and others. - harold
Not without an assembler library or an external tool. You could use machine code, though, like here. - Alexey Frunze

2 Answers

5
votes

Put the assembly in a macro and use the pre-processor to make the correct code.

#ifdef GCC
#define MY_ASM_CODE __asm() { blah blah blah}
#endif

#ifdef MSVC
#define MY_ASM_CODE __asm { blah blah blah }
#endif

int main(void)
{
  MY_ASM_CODE;
  return 0;
}
0
votes

As an alternative...

I presume you use Visual C because it's a Windows platform?

Why not use gcc for both Windows and Linux platforms?

Then it's the same source and same assembly format !