14

Yesterday I learned that inline assembly (with the __asm keyword) is not supported under Microsoft Visual C++ when compiling for AMD64 and Itanium targets.

Is that correct? And if so, does anyone know why they would not support inline assembly for those targets? It seems like a rather big feature to just drop...

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234

2 Answers2

13

Correct, it still isn't supported in VS 2010 Beta 1. My guess is that inline assembly is just too difficult to implement: the way Microsoft implemented it, it integrates with the surrounding C code so that data can flow in and out of the C code, and appropriate glue code is automatically injected. For that, the C compiler actually needs to understand the assembler code; they just haven't implemented that for AMD64 and Itanium.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • 1
    The C compiler generates ASM as an intermediate, there is nothing making it "difficult" for it to allow inline ASM on AMD64. The platform specs are the sole reason why inline ASM doesn't exist for x86_64 targets in several compilers that supported it for x86. – Mark K Cowan Dec 15 '13 at 16:26
  • 2
    @MarkKCowan: Have you *seen* MSVC's inline ASM? It involves an awful lot of do-what-I-mean; you can freely mix C/C++ variables in with the assembly code text, so the compiler has to parse and (on some level) analyze all of the code, not like GCC's way where the assembly code itself is specified in a style reminiscent of printf format strings, and explicit descriptions of the inputs, outputs and clobbered registers obviate any need for the compiler to attempt to analyze the assembly. Honestly, I prefer GCC's approach, as it involves less second-guessing the compiler. – SamB Feb 13 '16 at 18:02
  • 1
    @SamB yep, same as inline assembly in Delphi. I just wish GCC didn't use AT&T syntax :( – Mark K Cowan Feb 13 '16 at 18:09
  • 1
    @MarkKCowan Oh, certainly, AT&T syntax for Intel assembly is craptastic. And I'm not too crazy about GCC's actual constraint syntax (especially the documentation of that syntax), either. But assembly code is the **last** place I want to have to guess what the compiler will think some code is intended to do, and there are times when access to a full assembler has its uses... – SamB Feb 13 '16 at 18:28
6

It seems like a rather big feature to just drop...

It's quite easy to call a function written with an assembler, as long as you follow C conventions. This tutorial explains how.

Bastien Léonard
  • 60,478
  • 20
  • 78
  • 95
  • Agreed, the only real restriction is that you cannot mix C and ASM in the same routine. Coming from a Pascal background where inline ASM mixing is common in scientific code, I can fully agree with the decision to enforce separation of languages into different functions. – Mark K Cowan Aug 04 '13 at 20:22