CPUID ALL in ASM

Share your advanced PureBasic knowledge/code with the community.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

CPUID ALL in ASM

Post by michaeled314 »

Code: Select all

CPUName.s = Space(12)
pCPUName.l = @CPUName
FPU.l
VME.l


!XOR eax,eax
!CPUID
MOV eax,pCPUName
MOV [eax],ebx
MOV [eax+4],edx
MOV [eax+8],ecx
MOV CPUName,eax

MOV eax,1
!CPUID

BT eax,0
ADC FPU,0
BT eax,1
ADC VME,0
:)
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post by Blue »

Nice work. :shock:

Thanks for passing it on.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Well I tried to make it work but somethings wrong with it:

Code: Select all

CPUName.s = Space(12)
pCPUName.l = @CPUName
FPU.l
VME.l

!XOR eax,eax
!CPUID

!MOV eax,[v_pCPUName]
!MOV [eax],ebx
!MOV [eax+4],edx
!MOV [eax+8],ecx
!MOV [v_CPUName],eax

!MOV eax,1
!CPUID

!BT eax,0
!ADC [v_FPU],0
!BT eax,1
!ADC [v_VME],0

Debug CPUName
Debug FPU
Debug VME
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

Code: Select all

Procedure.s GetCPUName() 
  Protected Buffer.s 
  Protected Pointer1.l, Pointer2.l, Pointer3.l, Pointer4.l 
  
  !MOV eax, $80000002 
  !CPUID 
  !MOV [p.v_Pointer1], EAX
  !MOV [p.v_Pointer2], EBX
  !MOV [p.v_Pointer3], ECX 
  !MOV [p.v_Pointer4], EDX
  Buffer = PeekS(@Pointer1, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer2, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer3, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer4, 4, #PB_Ascii) 
  !MOV eax, $80000003 
  !CPUID 
  !MOV [p.v_Pointer1], EAX
  !MOV [p.v_Pointer2], EBX
  !MOV [p.v_Pointer3], ECX
  !MOV [p.v_Pointer4], EDX
  Buffer + PeekS(@Pointer1, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer2, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer3, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer4, 4, #PB_Ascii) 
  !MOV eax, $80000004 
  !CPUID 
  !MOV [p.v_Pointer1], EAX
  !MOV [p.v_Pointer2], EBX
  !MOV [p.v_Pointer3], ECX
  !MOV [p.v_Pointer4], EDX
  Buffer + PeekS(@Pointer1, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer2, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer3, 4, #PB_Ascii) 
  Buffer + PeekS(@Pointer4, 4, #PB_Ascii)   
  ProcedureReturn Buffer 
EndProcedure 

Debug GetCPUName()
I cant remember where the hell I came accross this bit of code.... maybe purearea? Either way, does the job.
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

yep thanks, although it looks quite messy to be frank with you :lol: :!:
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

LOL, yeah, it is a little messy. Lets see what can be done about that :P
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Post by Thunder93 »

Nice...!

Though using LuCiFeR[SD] code, the CPU Specification retrieved and not the actual CPU name. :?
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Post by breeze4me »

superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

yes, the actual x86 reference manual hosts a whopping 29 pages dedicated to this instruction only... I got lost at the second one :lol:
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

LuCiFeR[SD] wrote: I cant remember where the hell I came accross this bit of code.... maybe purearea?
The original posting was from ts-soft:
http://www.purebasic.fr/english/viewtop ... 29&start=3

Another ASM code example from the German forum by Helle:
http://www.purebasic.fr/german/viewtopic.php?t=13408
and
http://www.purebasic.fr/german/viewtopi ... 08&start=4 (returns unicode string)
Post Reply