PROWAREtech








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
Comment