PROWAREtech

articles » current » assembly » x86 » check-for-cpuid-support

x86 Assembly: How to Check for CPUID Support

An example of how to check if a processor supports the CPUID instruction.

This assembly code was compiled with MS Visual C++ Express Edition 2005 using the MACRO ASSEMBLER for MS Visual C++ Express Edition 2005.

This example is from the SSE/SSE2 tutorial.

TITLE 'extern "C" int __cdecl isCPUID();'
.686P
.model FLAT
PUBLIC	_isCPUID
_TEXT	SEGMENT
_isCPUID PROC NEAR
	
	push ebx         ; save ebx for the caller
	pushfd           ; push eflags on the stack
	pop eax          ; pop them into eax
	mov ebx, eax     ; save to ebx for restoring afterwards
	xor eax, 200000h ; toggle bit 21
	push eax         ; push the toggled eflags
	popfd            ; pop them back into eflags
	pushfd           ; push eflags
	pop eax          ; pop them back into eax
	cmp eax, ebx     ; see if bit 21 was reset
	jz not_supported
	
	mov eax, 1
	jmp exit
	
not_supported:
	xor eax, eax;

exit:
	pop ebx
	ret 0
_isCPUID ENDP
_TEXT	ENDS
END

PROWAREtech

Hello there! How can I help you today?
Ask any question

PROWAREtech

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE