All,
I'm working through a couple of assembler programs for linux which are describes in the book "Professional Assemble Language", Richard Blum, Wrox Press
and one example uses cpuid to display the name of the current cpu.
(It's a great book covering assembler for linux, and it even mentions Hutch and this forum)
Does anyone have an example of getting the other information available with this opcode?
Rgs, James.
#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
assemble and link with
as -o cpuid.o cpuid.s
ld -o cpuid cpuid.o
run with
./cpuid
Full details are in the intel instruction manuals - under "cpuid" (surprisingly :wink)
Hello,
I have found a sample of use searching for 3dnow at AMD site
Quote
The presence of the CPUID instruction is indicated by the ID
bit (21) in the EFLAGS register. If this bit is writable, the
CPUID instruction is supported. The following code sample
shows how to test for the presence of the CPUID instruction.
pushfd ; save EFLAGS
pop eax ; store EFLAGS in EAX
mov ebx, eax ; save in EBX for later testing
xor eax, 00200000h ; toggle bit 21
push eax ; put to stack
popfd ; save changed EAX to EFLAGS
pushfd ; push EFLAGS to TOS
pop eax ; store EFLAGS in EAX
cmp eax, ebx ; see if bit 21 has changed
jz NO_CPUID ; if no change, no CPUID
Quote
The following code sample shows how to test for the presence of
extended function 8000_0001h.
mov eax, 80000000h ; query for extended functions
CPUID ; get extended function limit
cmp eax, 80000000h ; is 8000_0001h supported?
jbe NO_EXTENDEDMSR ; if not, 3DNow! tech. not supported
Quote
The
following code sample shows how to test for 3DNow! instruction
support.
mov eax, 80000001h ; setup ext. function 8000_0001h
CPUID ; call the function
test edx, 80000000h ; test bit 31
jnz YES_3DNow! ; 3DNow! technology supported
ToutEnMasm
Ted, I know what the instruction does, but was looking for examples of it's full use.
Tout, thanks. Ill keep a book mark to this.
Also, here is the same example above done using intel syntax and the GNU Assembler.
#cpuid.s Sample program to extract the processor Vendor ID
.intel_syntax noprefix
.global _start
.data
output:
.ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n"
.text
_start:
nop
mov eax, 0
cpuid
mov edi, offset output
mov [edi + 28], ebx
mov [edi + 32], edx
mov [edi + 36], ecx
mov eax, 4
mov ebx, 1
mov ecx, offset output
mov edx, 42
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
Yes, and the details for what information you can get from it is in there :P
Quick example
.586
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
;***************************************************************************************************
.data
mbTitle db "Vendor String",0
.data?
buff db 256 dup (?)
.code
start:
mov eax,80000000h
cpuid
.IF (eax>=80000005h)
push edi
lea edi,[buff]
mov eax,80000002h
cpuid
mov [edi+00h],eax
mov [edi+04h],ebx
mov [edi+08h],ecx
mov [edi+0Ch],edx
mov eax,80000003h
cpuid
mov [edi+10h],eax
mov [edi+14h],ebx
mov [edi+18h],ecx
mov [edi+1Ch],edx
mov eax,80000004h
cpuid
mov [edi+20h],eax
mov [edi+24h],ebx
mov [edi+28h],ecx
mov [edi+2Ch],edx
mov eax,80000005h
cpuid
mov [edi+30h],eax
mov [edi+34h],ebx
mov [edi+38h],ecx
mov [edi+3Ch],edx
invoke MessageBox, NULL,edi,ADDR mbTitle,MB_OK or MB_ICONINFORMATION
pop edi
.ENDIF
invoke ExitProcess, NULL
end start
(Conversion to Linux just needs an int80 for printing the string, and one for exit.)
Hello,
This forum begin a real mine of informations,searching other thing,i find that
Win32asm studio project have a source on the subject
http://www.winasm.net/index.php?ind=downloads&op=entry_view&iden=48
ToutEnMasm
thanks both of you.
Ill add the above to my example for GAS an repost. Thanks.