// 获得 CPU 类型,用VC, console
#include < iostream >
using namespace std;
unsigned int SteppingID;
unsigned int Model;
unsigned int Family;
unsigned int ProcessorType;
unsigned char Brand;
unsigned long VersionInfo;
unsigned long FeatureInfo;
template < typename T >
void Print(char* a,T ret){
cout << a << ":\t"<< ret << endl;
}
void GetFeature(long i,char *str)
{
_asm xor ebx,ebx
_asm mov ebx,i
_asm bt FeatureInfo,ebx //"bt" is opcode to test a particular bit(on/off) in a string
//The bit number to test is provided as the second operand
//The result is stored in the carry flag
_asm jnc Feature_not_installed
cout << "CPU Feature: " << str << "\tO" << endl;
return;
Feature_not_installed:
cout << "CPU Feature: " << str << "\tX" << endl;
}
int main()
{
char *strFeatures[32]={
"FPU ",// x87 FPU on Chip
"VME ",// Virtual 8086 Enhancement
"DE ",// Debugging Extensions
"PSE ",// Page Size Extensions
"TSC ",// Time Stamp Counter
"MSR ",// RDMSR and WRMSR Support
"PAE ",// Physical Address Extensions
"MCE ",// Machine Check Exception
"CX8 ",// CMPXCHG8B instruction
"APIC ",// Advanced Programmable Interrupt Controller on Chip
" ", //Reserved 10
"SEP ",// SYSENTER and SYSEXIT
"MTRR ",// Memory Type Range Register
"PGE ",// PTE Global Bit
"MCA ",// Machine Check Architecture
"CMOV ",// Condtional Move/Compare Instruction
"PAT ",// Page Attribute Table
"PSE-32 ",// Page Size Extension
"PSN ",// Processor Serial Number
"CLFSH ",// CFLUSH Instruction
" ", //Reserved 20
"DS ",// Debug Store
"ACPI ",// Thermal Monitor and Clock Control
"MMX ",// MMX Technology
"FXSR ",// FXSAVE/FXRSTOR
"SSE ",// SSE Extensions
"SSE2 ",// SSE2 Extensions
"SS ",// Self Snoop
"HTT ",// Hyper Threading Tech
"TM ",//Thermal Monitor
" ", //Reserved 30
"PBE ",// Pend. Brk. En
};
// Show the Vendor ID. Should be "GenuineIntel" if the processor is Intel"/////////////
cout << "Processor Vendor: " << VendorID << endl;
//Store all the required information in memory////////////////////////////////////////
_asm
{
mov eax,1
cpuid //CPUID Instruction
mov VersionInfo,eax //Store Version Information
mov FeatureInfo,edx //Store Feature Information
mov Brand,bl //Store Brand Information
}
//Extract the SteppingID, model and family from the bit encoded VersionInfo and display
SteppingID = VersionInfo & 0x0F; //Stepping ID
Model = (VersionInfo & 0xF0)>> 4; //Model
Family = (VersionInfo & 0x0F00) >> 8; //Family
ProcessorType = (VersionInfo & 3000) >> 12; //Processor Type
Print("SteppingID", SteppingID);
Print("Model", Model);
Print("Family", Family);
//Show the Processor Type
Print("The Processor Type is",strProcessorType[ProcessorType]);