Advertisement
chino

CPUID

Oct 31st, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. void VendorID()
  7. {
  8.     unsigned long iEax = 0, iEbx = 0, iEcx = 0, iEdx = 0;
  9.     char szVenderID[12] = {'\0'};
  10.     __asm{
  11.         mov eax, 0x0000000
  12.         cpuid
  13.  
  14.         mov dword ptr[szVenderID+0], ebx
  15.         mov dword ptr[szVenderID+4], edx
  16.         mov dword ptr[szVenderID+8], ecx
  17.         mov byte ptr[szVenderID+12], '\0'
  18.  
  19.         mov iEax, eax
  20.         mov iEbx, ebx
  21.         mov iEcx, ecx
  22.         mov iEdx, edx
  23.     }
  24.  
  25.     cout << "**** eax = 0x0000000 ****\n";
  26.     cout << "EAX:0x" << setw(8) << setfill('0') << hex << iEax << endl;
  27.     cout << "EBX:0x" << setw(8) << setfill('0') << hex << iEbx << endl;
  28.     cout << "ECX:0x" << setw(8) << setfill('0') << hex << iEcx << endl;
  29.     cout << "EDX:0x" << setw(8) << setfill('0') << hex << iEdx << endl;
  30.     cout << "Vendor ID is " << szVenderID << endl;
  31.     cout << "\n";
  32.  
  33.     return;
  34. }
  35.  
  36. void ProcesserSerialNumber()
  37. {
  38.     unsigned long iEax = 0, iEbx = 0, iEcx = 0, iEdx = 0;
  39.     __asm{
  40.         mov eax, 0x0000003
  41.         cpuid
  42.  
  43.         mov iEax, eax
  44.         mov iEbx, ebx
  45.         mov iEcx, ecx
  46.         mov iEdx, edx
  47.     }
  48.  
  49.     cout << "**** eax = 0x00000003 ****\n";
  50.     cout << "EAX:0x" << setw(8) << setfill('0') << hex << iEax << endl;
  51.     cout << "EBX:0x" << setw(8) << setfill('0') << hex << iEbx << endl;
  52.     cout << "ECX:0x" << setw(8) << setfill('0') << hex << iEcx << endl;
  53.     cout << "EDX:0x" << setw(8) << setfill('0') << hex << iEdx << endl;
  54.     cout << "\n";
  55.  
  56.     return;
  57. }
  58.  
  59. void HighestExtendedFunctionSupported()
  60. {
  61.     unsigned long iEax = 0, iEbx = 0, iEcx = 0, iEdx = 0;
  62.     __asm{
  63.         mov eax, 80000000h
  64.         cpuid
  65.  
  66.         mov iEax, eax
  67.     }
  68.     cout << "**** eax = 80000000h ****\n";
  69.     cout << "EAX:0x" << setw(8) << setfill('0') << hex << iEax << endl;
  70.     cout << "\n";
  71.  
  72.     return;
  73. }
  74.  
  75. void ProcessorBrandString()
  76. {
  77.     char szPBS[48] = {'\0'};
  78.     __asm{
  79.         mov eax, 80000002h
  80.         cpuid
  81.  
  82.         mov dword ptr[szPBS+0], eax
  83.         mov dword ptr[szPBS+4], ebx
  84.         mov dword ptr[szPBS+8], ecx
  85.         mov dword ptr[szPBS+12], edx
  86.  
  87.         mov eax, 80000003h
  88.         cpuid
  89.  
  90.         mov dword ptr[szPBS+16], eax
  91.         mov dword ptr[szPBS+20], ebx
  92.         mov dword ptr[szPBS+24], ecx
  93.         mov dword ptr[szPBS+28], edx
  94.  
  95.         mov eax, 80000004h
  96.         cpuid
  97.  
  98.         mov dword ptr[szPBS+32] ,eax
  99.         mov dword ptr[szPBS+36], ebx
  100.         mov dword ptr[szPBS+40], ecx
  101.         mov dword ptr[szPBS+44], edx
  102.         mov word ptr[szPBS+48], '\0'
  103.  
  104.     }
  105.  
  106.     cout << "**** eax = 80000002h, 80000003h, 80000004h ****\n";
  107.     cout << "Processor Brand String : " << szPBS << endl;
  108.     cout << "\n";
  109.  
  110.     return;
  111. }
  112.  
  113. void main()
  114. {
  115.     ios::sync_with_stdio(false);
  116.     cin.tie(0);
  117.  
  118.     VendorID();
  119.  
  120.     ProcesserSerialNumber();
  121.  
  122.     HighestExtendedFunctionSupported();
  123.    
  124.     ProcessorBrandString();
  125.  
  126.     cin.get();
  127.  
  128.     return;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement