Current location - Trademark Inquiry Complete Network - Trademark inquiry - C language programming to obtain cpu information
C language programming to obtain cpu information
Have a patient look, the operation has passed, I hope it will help you!

# include & ltstdio.h & gt

Unsigned int veax

Unsigned int vebx

Unsigned int vedx

Unsigned int vecx

//Execute the CPUID instruction

Void cpuid (unsigned integer veax 1)

{

_asm{

mov eax,veax 1

cpuid

mov veax,eax

mov vebx,ebx

mov vecx,ecx

mov vedx,edx

}

}

//Shift the ASCII code in the register and output it as a character.

Void LeftMove (unsigned integer variable)

{

printf("%c ",var);

for(int I = 0; I<3; i++)

{

var =(var & gt; & gt;

printf("%c ",var);

}

}

//Shift and output the value in the register as "%d".

Void LM (unsigned integer variable)

{

printf("%d ",var);

for(int I = 0; I<3; i++)

{

var =(var & gt; & gt;

printf("%d ",var);

}

}

//Get CPU vendors (when EAX value is 0) and store them in EBX, EDX and ECX in turn.

void getCpuName()

{

cpuid(0);

left move(vebx);

left move(vedx);

left move(vecx);

printf("\

";

}

//Get the trademark of CPU. When the values in EAX are 0x80000003 and 0x80000004, respectively, 16 characters are returned to form a trademark.

//Store in EAX, EBX, ECX and EDX in turn.

void getCpuBrand()

{

for(int j = 0; j & lt2; j++)

{

cpuid(0x 80000003+j);

left move(veax);

left move(vebx);

left move(vecx);

left move(vedx);

}

printf("\

";

}

//Get the characteristics of CPU, the parameter is eax = 1, and the return value is put in edx and ecx. After verifying a bit edx or ecx,

//You can get whether a certain feature of the CPU is supported. For example, the 32nd bit of edx indicates whether MMX is supported.

//The 28th bit of //edx indicates whether Hyper-Threading is supported, and the 7th bit of ecx indicates whether speed sted is supported.

void getCpuFeature()

{//Because there are too many functions, you can't write one by one. Write it out when necessary. The method is the same.

}

//It takes two steps to get the serial number of the CPU. First, eax = 1 as a parameter, the returned eax stores the upper two words of the serial number.

//Take eax = 3 as the parameter, return ecx and edx, and store the first four words from low to high.

void getCpuSeris()

{

cpuid( 1);

LM(veax);

cpuid(3);

LM(vecx);

LM(vedx);

printf("\

";

}

void main()

{

getCpuName();

getCpuBrand();

getCpuSeris();

}