Assembly Language Help ;)
Hi,
I'm running some simple assembler code to try and get the details of the CPU. I'm compiling using Code::Blocks so here is the code ;)
Code:
#include <iostream>
int main()
{
int i = 0;
char* ptr1 = new char[4];
std::cout << ptr1 << std::endl;
asm("movl %1, %%eax; CPUID; movl %%ebx, %0;"
:"=r"(ptr1) // output %0
:"r"(i) // input %1
:"%eax","%ebx");
std::cout << ptr1[0] << std::endl;
return 1;
}
Ok but I'm having some problems. As far as I understand it, the CPUID instruction causes data to be written into the registers ebx,ecx and edx. Ok great 4 bytes a piece. So I made a char array which can hold 4 chars, 1 byte each. I move the int 0 into eax and then commence the instruction and then move the first 4 bytes coming from ebx to the pointer variable.
I'm doing something wrong here though. I get the feeling this is too simplified, but I really don't know how to progress. Can anyone offer any insight here? Many thanks ;)