2016-08-29 1 views
1

Ich versuche this c source file mit cl.exe (von Visual Studio) zu kompilieren. Der spezifische Code in Frage, die kompilieren versagt ist:Kompiliere c-Quelle mit 'asm' Direktive

#include <stdio.h> 

static inline void native_cpuid(unsigned int *eax, unsigned int *ebx, 
           unsigned int *ecx, unsigned int *edx) 
{ 
     /* ecx is often an input as well as an output. */ 
     asm volatile("cpuid" 
      : "=a" (*eax), 
       "=b" (*ebx), 
       "=c" (*ecx), 
       "=d" (*edx) 
      : "0" (*eax), "2" (*ecx)); 
} 

Ich sehe diesen Fehler:

C:\>cl sgx.c 
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x86 
Copyright (C) Microsoft Corporation. All rights reserved. 

sgx.c 
sgx.c(7): error C2065: 'asm': undeclared identifier 
sgx.c(7): error C2143: syntax error: missing ';' before 'volatile' 
+3

Sieht aus wie gcc erweiterte Inline-Asm. Ich glaube nicht, dass VS es verstehen kann. Verwenden Sie einen anderen Compiler. – EOF

+1

Haben Sie '__asm' anstelle von' asm' probiert? –

+3

Das scheint der erweiterte Inline-Assembler von GCC zu sein, der mit MSVC inkompatibel ist. MSVC hat jetzt den Compiler intrinsischen '__cpuid' dokumentiert hier: https://msdn.microsoft.com/en-us/library/hskdteyh.aspx. Ich würde Ihre 'cpuid' Funktion konvertieren, um den intrinsischen anstelle des Inline-Assemblers zu verwenden. –

Antwort