0

I just want to get my vendor ID, i.e. GenuineIntel using cpuid in C.

This is the function I want to use:

void __cpuid(
   int cpuInfo[4],
   int function_id
);

This is my wrong code:

int main(){
  int cpuInfo[4];
__cpuid(cpuInfo, 1);
}
user204415
  • 307
  • 1
  • 4
  • 20

2 Answers2

0

Assuming you are running on Windows, you need to add #include <intrin.h> to your code. See here.

markgz
  • 6,054
  • 1
  • 19
  • 41
0
#include <string.h>
#include <locale.h>
#include <intrin.h>
#include <stdio.h>

// Prototipos
int LeeIDFabricante (char * CadFabricante);
//void LeeIDModelo (char * CadenaModelo);


int main(int argc, char *argv[])
{
    char CadFabricante[0x20];
    char CadenaModelo[0x40];
    int Resultado;
    setlocale( LC_ALL, "Spanish" );

    Resultado = LeeIDFabricante(CadFabricante);
    CadFabricante[12]='\0';
    printf("\nLa identificacion del fabricante es: %s. El maximo valor de CPUID es %d.\n", CadFabricante, Resultado);

    //LeeIDModelo(CadenaModelo);
    //printf("\nLa cadena de modelo es: %s\n", CadenaModelo);

    printf("\nPulse tecla RETORNO para terminar\n");
    getchar();

    return 0;
}

int LeeIDFabricante (char *CadFabricante)
{
    int p[4] = {-1};

    __cpuid(p, 0);
    memset(CadFabricante, 0, sizeof(CadFabricante));
    *((int*)CadFabricante) = p[1];
    *((int*)(CadFabricante+4)) = p[3];
    *((int*)(CadFabricante+8)) = p[2];

    return p[0];
}
user204415
  • 307
  • 1
  • 4
  • 20
  • 2
    Answers which are just code are not the most useful. Can you expand the answer please? – mjs Mar 03 '15 at 23:04