2016-08-29 6 views
1

Visual Studio의 cl.exe를 사용하여 this c source file을 컴파일하려고합니다. 컴파일에 실패 문제의 특정 코드는 다음과 같습니다'asm'지시문을 사용하여 C 소스 컴파일

대신 직접 어셈블리의
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

gcc 확장 인라인 asm처럼 보입니다. 나는 VS가 그것을 이해할 수 있다고 생각하지 않는다. 다른 컴파일러를 사용하십시오. – EOF

+1

당신은'asm' 대신'__asm'을 시도 했습니까? –

+3

MSVC와 호환되지 않는 GCC의 확장 인라인 어셈블러 인 것 같습니다. MSVC는 이제 컴파일러 본질적인'__cpuid' 문서를 가지고 있습니다 : https://msdn.microsoft.com/en-us/library/hskdteyh.aspx. 나는'cpuid' 함수를 인라인 어셈블러 대신 intrinsic을 사용하도록 변환 할 것입니다. –

답변

2

, 당신은 컴파일러 내장 함수를 사용할 수 있습니다

#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)); 
} 

나는이 실패를보고 있어요. 마이크로 소프트 컴파일러 지원 __cpuid() 여기에 설명 : https://msdn.microsoft.com/en-us/library/hskdteyh.aspx

GCC 대신 지원 __get_cpuid()cpuid.h를 통해이 답변 (https://stackoverflow.com/a/14266932/1401351)에 의해 설명한다.