Is there a way to insert assembly code into C?

Nathan picture Nathan · Sep 14, 2008 · Viewed 77.1k times · Source

I remember back in the day with the old borland DOS compiler you could do something like this:

asm {
 mov ax,ex
 etc etc...
}

Is there a semi-platform independent way to do this now? I have a need to make a BIOS call, so if there was a way to do this without asm code, that would be equally useful to me.

Answer

Niall picture Niall · Sep 14, 2008

Using GCC

__asm__("movl %edx, %eax\n\t"
        "addl $2, %eax\n\t");

Using VC++

__asm {
  mov eax, edx
  add eax, 2
}