fredrik.eriksson

Coffee and a keyboard

Merry Christmas to your AMD64

AMD have made the coolest Easter egg yet :) Compile and run this code on your AMD64

Merry Christmas.

#include <stdio.h>
inline void cpuid(unsigned int op, unsigned int *eax,
                  unsigned int *ebx, unsigned int *ecx,
                  unsigned int *edx)
{
    __asm__("cpuid"
    : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
    : "a" (op)
    : "cc");
}

int main(void)
{
    unsigned int eax,ebx,ecx,edx;
    unsigned int i=0;
    char array[17];
    char *cp=array;

    cpuid(0x8fffffff, &eax,&ebx,&ecx,&edx);

    for (i = 0; i < 4; i++)
        *cp++ = eax >> (8 * i);
    for (i = 0; i < 4; i++)
        *cp++ = ebx >> (8 * i);
    for (i = 0; i < 4; i++)
        *cp++ = ecx >> (8 * i);
    for (i = 0; i < 4; i++)
        *cp++ = edx >> (8 * i);
    *cp = 0;

    printf ("%s\n", array);
}