Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3795634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:06:49+00:00 2026-05-19T13:06:49+00:00

I would like to know if somebody around here has some good examples of

  • 0

I would like to know if somebody around here has some good examples of a C++ CPUID implementation that can be referenced from any of the managed .net languages.

Also, should this not be the case, should I be aware of certain implementation differences between X86 and X64?

I would like to use CPUID to get info on the machine my software is running on (crashreporting etc…) and I want to keep everything as widely compatible as possible.

Primary reason I ask is because I am a total noob when it comes to writing what will probably be all machine instructions though I have basic knowledge about CPU registers and so on…

Before people start telling me to Google: I found some examples online, but usually they were not meant to allow interaction from managed code and none of the examples were aimed at both X86 and X64. Most examples appeared to be X86 specific.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:06:50+00:00Added an answer on May 19, 2026 at 1:06 pm

    Accessing raw CPUID information is actually very easy, here is a C++ class for that which works in Windows, Linux and OSX:

    #ifndef CPUID_H
    #define CPUID_H
    
    #ifdef _WIN32
    #include <limits.h>
    #include <intrin.h>
    typedef unsigned __int32  uint32_t;
    
    #else
    #include <stdint.h>
    #endif
    
    class CPUID {
      uint32_t regs[4];
    
    public:
      explicit CPUID(unsigned i) {
    #ifdef _WIN32
        __cpuid((int *)regs, (int)i);
    
    #else
        asm volatile
          ("cpuid" : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
           : "a" (i), "c" (0));
        // ECX is set to zero for CPUID function 4
    #endif
      }
    
      const uint32_t &EAX() const {return regs[0];}
      const uint32_t &EBX() const {return regs[1];}
      const uint32_t &ECX() const {return regs[2];}
      const uint32_t &EDX() const {return regs[3];}
    };
    
    #endif // CPUID_H
    

    To use it just instantiate an instance of the class, load the CPUID instruction you are interested in and examine the registers. For example:

    #include "CPUID.h"
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char *argv[]) {
      CPUID cpuID(0); // Get CPU vendor
    
      string vendor;
      vendor += string((const char *)&cpuID.EBX(), 4);
      vendor += string((const char *)&cpuID.EDX(), 4);
      vendor += string((const char *)&cpuID.ECX(), 4);
    
      cout << "CPU vendor = " << vendor << endl;
    
      return 0;
    }
    

    This Wikipedia page tells you how to use CPUID: http://en.wikipedia.org/wiki/CPUID

    EDIT: Added #include <intrin.h> for Windows, per comments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at
I would like to know the reasons that we do refactoring and justify it.
I would like to know if somebody knows a library to changing the playback
I would like to know if somebody knows free custom nice controls for .NET
I would like to know your experience when you need to take over somebody
I would like to know that the request was due to the refresh button
I would like to know when somebody locked a file in an SVN repository,
I would like to know if somebody knows how to animate the translation of
Could somebody help me with this. I would like to know how to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.