下面是一个CPUID的ASM,我用MASM,TASM,NASM就是编译不过去呀。
这个ASM中VC工程中的一个文件上,VC也编译不过去呀。VC是不是只能编译在线汇编呀?
;/******************************************************************************
; * *
; * cpuid.asm, check cpu features *
; * *
; * Copyright (C) 2001 - Michael Militzer <[email protected]>, *
; * *
; * For more information visit the XviD homepage: http://www.xvid.org *
; * *
; ******************************************************************************/
;
;/******************************************************************************
; * *
; * Revision history: *
; *
; * 01.06.2002 added more functionality, Sigma Designs. *
; * 17.12.2001 initial version (Isibaar) *
; * *
; ******************************************************************************/;
bits 32%define CPUID_MMX 0x00800000
%define CPUID_SSE 0x02000000
%define CPUID_SSE2 0x04000000%define EXT_CPUID_3DNOW 0x80000000
%define EXT_CPUID_AMD_3DNOWEXT 0x40000000
%define EXT_CPUID_AMD_MMXEXT 0x00400000%define MP4V_CPU_MMX 0x00010000
%define MP4V_CPU_MMXEXT 0x00020000
%define MP4V_CPU_SSE 0x00040000
%define MP4V_CPU_SSE2 0x00080000
%define MP4V_CPU_3DNOW 0x00100000
%define MP4V_CPU_3DNOWEXT 0x00200000section .dataalign 32vendorSigma db "SigmaDesigns"
vendorIntel db "GenuineIntel"
vendorAMD db "AuthenticAMD"
vendor dd 0,0,0
cpu_brand dd 0 ;address to return cpu_brand
features dd 0; Compare the vendor string
%macro CompareVendors 2
lea esi, [%1]
lea edi, [%2]
mov ecx, 12
cld
repe cmpsb
%endmacro; Assume the cpu cap feature is in edx
%macro CPU_FEATURES 3
mov ecx, %1
mov eax, %2
and eax, edx
neg eax ; if eax!=0, CF is set; else CF=0
sbb eax, eax ; eax = eax - eax - CF
and eax, ecx
or [%3], eax%endmacrosection .textalign 64
;----------------------------------
; int get_cpu_cap(char *name)
;----------------------------------global _get_cpu_cap
_get_cpu_cap
mov eax, [esp+4] ; point of string
mov [cpu_brand], eax
xor eax, eax
mov [features], eax ; reset output features pushad
pushfd
; CPUID command ?
pop eax
mov ebx, eax
xor eax, 0x200000
push eax
popfd
pushfd
pop eax
cmp eax, ebx jz near quit_test ; no CPUID supported, goto exit
xor eax, eax ; get vendor string, store them into [vendor]
cpuid
lea edi, [vendor]
mov [edi], ebx ; save vendor's name
mov [edi+4], edx
mov [edi+8], ecx or eax, eax
jz near quit_test mov eax, 1 ; get cap of CPU
cpuid ; MMX support ?
CPU_FEATURES MP4V_CPU_MMX, CPUID_MMX, features ; SSE support ?
CPU_FEATURES (MP4V_CPU_MMXEXT+MP4V_CPU_SSE), CPUID_SSE, features ; SSE2 support?
CPU_FEATURES MP4V_CPU_SSE2, CPUID_SSE2, features ; check if cpu_brand string supported ?
mov eax, 0x80000000
cpuid
cmp eax, 0x80000000
jbe near quit_test mov edi, [cpu_brand]
mov eax, 0x80000002
cpuid
mov [edi], eax
mov [edi+4], ebx
mov [edi+8], ecx
mov [edi+12], edx
mov eax, 0x80000003
cpuid
mov [edi+16], eax
mov [edi+20], ebx
mov [edi+24], ecx
mov [edi+28], edx mov eax, 0x80000004
cpuid
mov [edi+32], eax
mov [edi+36], ebx
mov [edi+40], ecx
mov [edi+44], edx ; check if cpu_brand string supported ?
mov eax, 0x80000000
cpuid
cmp eax, 0x80000000
jbe near quit_test ; Intel cpu ?
;CompareVendors vendorIntel, vendor
;jz quit_testamd_test: ; AMD cpu ?
;CompareVendors vendorAMD, vendor
;jnz quit_test
lea esi, [vendorAMD]
lea edi, [vendor]
mov ecx, 12
cld
repe cmpsb
jnz quit_test ; 3DNow! support ?
CPU_FEATURES MP4V_CPU_3DNOW, EXT_CPUID_3DNOW, features ; extended MMX ?
CPU_FEATURES MP4V_CPU_MMXEXT, EXT_CPUID_AMD_MMXEXT, features ; 3DNOW extended ?
CPU_FEATURES MP4V_CPU_3DNOWEXT, EXT_CPUID_AMD_3DNOWEXT, features
quit_test:
lea esi, [vendorSigma]
mov edi, [cpu_brand]
mov ebx, [esi]
mov ecx, [esi+4]
mov edx, [esi+8]
mov [edi], ebx
mov [edi+4], ecx
mov [edi+8], edx
xor ebx, ebx
mov [edi+12], eax popad mov eax, [features]
ret
这个ASM中VC工程中的一个文件上,VC也编译不过去呀。VC是不是只能编译在线汇编呀?
;/******************************************************************************
; * *
; * cpuid.asm, check cpu features *
; * *
; * Copyright (C) 2001 - Michael Militzer <[email protected]>, *
; * *
; * For more information visit the XviD homepage: http://www.xvid.org *
; * *
; ******************************************************************************/
;
;/******************************************************************************
; * *
; * Revision history: *
; *
; * 01.06.2002 added more functionality, Sigma Designs. *
; * 17.12.2001 initial version (Isibaar) *
; * *
; ******************************************************************************/;
bits 32%define CPUID_MMX 0x00800000
%define CPUID_SSE 0x02000000
%define CPUID_SSE2 0x04000000%define EXT_CPUID_3DNOW 0x80000000
%define EXT_CPUID_AMD_3DNOWEXT 0x40000000
%define EXT_CPUID_AMD_MMXEXT 0x00400000%define MP4V_CPU_MMX 0x00010000
%define MP4V_CPU_MMXEXT 0x00020000
%define MP4V_CPU_SSE 0x00040000
%define MP4V_CPU_SSE2 0x00080000
%define MP4V_CPU_3DNOW 0x00100000
%define MP4V_CPU_3DNOWEXT 0x00200000section .dataalign 32vendorSigma db "SigmaDesigns"
vendorIntel db "GenuineIntel"
vendorAMD db "AuthenticAMD"
vendor dd 0,0,0
cpu_brand dd 0 ;address to return cpu_brand
features dd 0; Compare the vendor string
%macro CompareVendors 2
lea esi, [%1]
lea edi, [%2]
mov ecx, 12
cld
repe cmpsb
%endmacro; Assume the cpu cap feature is in edx
%macro CPU_FEATURES 3
mov ecx, %1
mov eax, %2
and eax, edx
neg eax ; if eax!=0, CF is set; else CF=0
sbb eax, eax ; eax = eax - eax - CF
and eax, ecx
or [%3], eax%endmacrosection .textalign 64
;----------------------------------
; int get_cpu_cap(char *name)
;----------------------------------global _get_cpu_cap
_get_cpu_cap
mov eax, [esp+4] ; point of string
mov [cpu_brand], eax
xor eax, eax
mov [features], eax ; reset output features pushad
pushfd
; CPUID command ?
pop eax
mov ebx, eax
xor eax, 0x200000
push eax
popfd
pushfd
pop eax
cmp eax, ebx jz near quit_test ; no CPUID supported, goto exit
xor eax, eax ; get vendor string, store them into [vendor]
cpuid
lea edi, [vendor]
mov [edi], ebx ; save vendor's name
mov [edi+4], edx
mov [edi+8], ecx or eax, eax
jz near quit_test mov eax, 1 ; get cap of CPU
cpuid ; MMX support ?
CPU_FEATURES MP4V_CPU_MMX, CPUID_MMX, features ; SSE support ?
CPU_FEATURES (MP4V_CPU_MMXEXT+MP4V_CPU_SSE), CPUID_SSE, features ; SSE2 support?
CPU_FEATURES MP4V_CPU_SSE2, CPUID_SSE2, features ; check if cpu_brand string supported ?
mov eax, 0x80000000
cpuid
cmp eax, 0x80000000
jbe near quit_test mov edi, [cpu_brand]
mov eax, 0x80000002
cpuid
mov [edi], eax
mov [edi+4], ebx
mov [edi+8], ecx
mov [edi+12], edx
mov eax, 0x80000003
cpuid
mov [edi+16], eax
mov [edi+20], ebx
mov [edi+24], ecx
mov [edi+28], edx mov eax, 0x80000004
cpuid
mov [edi+32], eax
mov [edi+36], ebx
mov [edi+40], ecx
mov [edi+44], edx ; check if cpu_brand string supported ?
mov eax, 0x80000000
cpuid
cmp eax, 0x80000000
jbe near quit_test ; Intel cpu ?
;CompareVendors vendorIntel, vendor
;jz quit_testamd_test: ; AMD cpu ?
;CompareVendors vendorAMD, vendor
;jnz quit_test
lea esi, [vendorAMD]
lea edi, [vendor]
mov ecx, 12
cld
repe cmpsb
jnz quit_test ; 3DNow! support ?
CPU_FEATURES MP4V_CPU_3DNOW, EXT_CPUID_3DNOW, features ; extended MMX ?
CPU_FEATURES MP4V_CPU_MMXEXT, EXT_CPUID_AMD_MMXEXT, features ; 3DNOW extended ?
CPU_FEATURES MP4V_CPU_3DNOWEXT, EXT_CPUID_AMD_3DNOWEXT, features
quit_test:
lea esi, [vendorSigma]
mov edi, [cpu_brand]
mov ebx, [esi]
mov ecx, [esi+4]
mov edx, [esi+8]
mov [edi], ebx
mov [edi+4], ecx
mov [edi+8], edx
xor ebx, ebx
mov [edi+12], eax popad mov eax, [features]
ret
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货