The C ++ programming language has a wide range of applications. Many of these functions can help us meet certain requirements and improve programming efficiency to a certain extent. Here we will introduce some application methods for the C ++ cpuid command for your convenience.
- Overview of basic concepts of C ++ class template Specialization
- Understand the basic concepts of C ++ non-type template parameters
- Summary of precautions for using non-type parameters in C ++ function templates
- C ++ typename different application methods
- C ++ memory allocation skills
1. What is the C ++ cpuid command?
The CPUID command is an assembly command for obtaining CPU information in intel IA32 architecture. It can be used to obtain CPU-related items such as CPU type, model, manufacturer information, trademark information, serial number, and cache.
2. Use of the C ++ cpuid command
Cpuid uses eax as the input parameter, eax, ebx, ecx, and edx as the output parameter. For example:
- __asm
- {
- mov eax, 1
- cpuid
- ...
- }
The above Code takes 1 as the input parameter. After the cpuid is executed, the values of all registers are filled with the returned values. For the eax values of different input parameters, the output parameters have different meanings. To better use the cpuid command in C ++, classes can be used to encapsulate the command. A special function is defined in the class to execute the cpuid, and an input parameter is required. You also need to define four member variables to store the values returned after the C ++ cpuid command is executed. Since these four registers are 32-bit long, you can use the unsinged long type variable storage.
- Typedef unsigned long DWORD
- Class CPUID
- {
- Public:
- ...
- Private:
- Void Executecpuid (DWORD eax); // used to implement cpuid
- DWORD m_eax; // store the returned eax
- DWORD m_ebx; // store the returned ebx
- DWORD m_ecx; // store the returned ecx
- DWORD m_edx; // store the returned edx
- ...
- }
- Void CPUID: Executecpuid (DWORD veax)
- {
- // Because embedded assembly code cannot identify class member variables
- // Define four temporary variables as transition
- DWORD deax;
- DWORD debx;
- DWORD decx;
- DWORD dedx;
- _ Asm
- {
- Mov eax, veax; move the input parameters to eax
- Cpuid; run cpuid
- Mov deax and eax; the following four lines of code store the variables in the Register into temporary variables:
- Mov debx, ebx
- Mov decx, ecx
- Mov dedx, edx
- }
- M_eax = deax; // put the content in the temporary variable into the class member variable
- M_ebx = debx;
- M_ecx = decx;
- M_edx = dedx;
- }
In this way, you can directly call the Executecupid () function to execute the C ++ cpuid command. The returned values include m_eax, m_ebx, m_ecx, and m_edx.