Skip to content

Instantly share code, notes, and snippets.

@kevroletin
Created December 1, 2010 21:34
Show Gist options
  • Save kevroletin/724269 to your computer and use it in GitHub Desktop.
Save kevroletin/724269 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <vector>
#include <algorithm>
const char L[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
void pr_hex(int i, int k = 0)
{
if (k == 16) return;
pr_hex(i / 16, k + 1);
printf("%c", L[i % 16]);
if (!(k % 4)) printf(" ");
}
short count;
int arr[4];
int a, b, c, d;
int main()
{
count = 4;
for (int i = 0; i < count; ++i)
{
asm volatile(
"movl $0x4, %%eax; \n"
"cpuid;"
:"=a"(a), "=b"(b), "=c"(c), "=d"(d)
:"c"(i)
:
);
printf("%d", count);
// 0 0000
// 1 0001
// 2 0010
// 3 0011
// 4 0100
// 5 0101
// 6 0110
// 8 0111
// 9 1000
// 10 1001
// a 1010
// b 1011
// c 1100
// d 1101
// e 1110
// f 1111
//1111 1111 1100 0000 0000 0000 0000 0000;
int m1 = 0xffc00000;
//0000 0000 0011 1111 1111 0000 0000 0000;
int m2 = 0x003ff000;
//0000 0000 0000 0000 0000 1111 1111 1111;
int m3 = 0x00000fff;
printf("%d", (b & m1 + 1)*(b & m2 + 1)*(b & m3)*(c + 1));
printf("\n");
}
return 0;
count = 1;
for (int i = 0; i < count; ++i)
{
asm volatile(
"movl $2, %eax;"
"cpuid;"
"movb %al, (_count);"
"movl %eax, (_a);"
"movl %ebx, (_a + 1);"
"movl %ecx, (_a + 2);"
"movl %edx, (_a + 3);"
);
for (int i = 0; i < 4; ++i)
{
pr_hex(arr[i]);
printf("\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment