I am trying to access the Information using CPUID in C++.
I have produced this code so far and could not go any longer.
I found some useful articles here and on the web but they did not seem to help me.
I am supposed to use instructions and registers from x88 only.
This is the code.
int b[5] = {0} ;
for (int a = 0; a < 5 ; a++)
{
__cpuid (b,a) ;
std::cout << "The code " << a << " gives " << b[0] << std::endl;
}
I am unable to go any further as I cannot understand how to fetch the information from this array bitwise. I have this wiki and msdn article which explains the scheme.
My question is not very good but I would appreciate any help or direction in this regard.
I suppose your problem is not about accessing the array data through an index, which is as you already done
b[0],b[1]and so on. You need a little bit of bit (!) manipulation. You have to mask out the bits you are not interested in and interpret what is left; e.g.will give you 4 bits (4-7) that are the model according to MSDN. And so on. Consider the following
(int supposed 32 bit int — or wider)
If you want e.g. the processor type, you need:
and then shift (logical shift) right of 3 “nibbles” (12). So
will give you a number representing processor type. (The number 3 is 11 in base 2, so it’s the right mask to select only the rightmost two bits).