PROWAREtech

articles » current » assembly » x86 » retrieve-cpu-brand-with-cpuid

x86 Assembly: How to Retrieve the CPU Name with CPUID

An example of how to retrieve the CPU brand or name using 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.

TITLE 'extern "C" int __cdecl cpu_brand(char *brand);'
.686P
.model FLAT
PUBLIC	_cpu_brand
_TEXT	SEGMENT
_cpu_brand PROC NEAR
	
	push ebx
	
	mov eax, 80000000h
	cpuid
	cmp eax, 80000004h
	jnge not_supported

	mov esi, [esp+(1+1)*4]

	mov eax, 80000002h
	cpuid
	mov [esi], eax
	mov [esi+4], ebx
	mov [esi+8], ecx
	mov [esi+12], edx

	mov eax, 80000003h
	cpuid
	mov [esi+16], eax
	mov [esi+20], ebx
	mov [esi+24], ecx
	mov [esi+28], edx

	mov eax, 80000004h
	cpuid
	mov [esi+32], eax
	mov [esi+36], ebx
	mov [esi+40], ecx
	mov [esi+44], edx

	mov eax, 1
	jmp exit
	

not_supported:
	xor eax, eax
	
exit:
	pop ebx
	ret 0
_cpu_brand ENDP
_TEXT	ENDS
END

Example usage / driver code:

#include <iostream>

extern "C" int __cdecl cpu_brand(char *brand);

int main(int argc, char *argv[])
{
	char brand[48+1];
	brand[48] = 0;
	if(cpu_brand(brand))
	{
		std::cout << brand << std::endl;
	}
	return 0;
}

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.
ACCEPT REJECT