I'm trying to read the information of the CPU by the CPUID instruction. With Dev C++ I've wrote this code:
int rEBX, rECX, rEDX;
asm {
MOV EAX, 0
CPUID
MOV DWORD PTR rEBX, EBX
MOV DWORD PTR rECX, ECX
MOV DWORD PTR rEDX, EDX
}
How can I write this in AT&T syntax for gcc?
Using CPUID with GCC
- AlfaOmega08
- Member
- Posts: 226
- Joined: Wed Nov 07, 2007 12:15 pm
- Location: Italy
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Some time ago, I posted my own CPUID implementation on the forums.. you're free to take a look at it.
But as for your question:
You may wish to expand that into a function though... whichever makes it easier.
The basic syntax is:
Hope that helps..
But as for your question:
Code: Select all
#define cpuid(in, a, b, c, d) \
__asm__ __volatile__("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
The basic syntax is:
Code: Select all
__asm__ ("instruction"
: outputs
: inputs
: clobbered registers
);
http://www.webservertalk.com/archive107 ... 23775.html
Richard Blum wrote:orCode: Select all
#cpuid2.s View the CPUID Vendor ID string using C library calls .section .datatext output: .asciz "The processor Vendor ID is '%s'\n" .section .bss .lcomm buffer, 12 .section .text .globl _start _start: movl $0, %eax cpuid movl $buffer, %edi movl %ebx, (%edi) movl %edx, 4(%edi) movl %ecx, 8(%edi) pushl $buffer pushl $output call printf addl $8, %esp pushl $0 call exit
Code: Select all
#cpuid.s Sample program to extract the processor Vendor ID .section .data output: .ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n" .section .text .globl _start _start: movl $0, %eax cpuid movl $output, %edi movl %ebx, 28(%edi) movl %edx, 32(%edi) movl %ecx, 36(%edi) movl $4, %eax movl $1, %ebx movl $output, %ecx movl $42, %edx int $0x80 movl $1, %eax movl $0, %ebx int $0x80