Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Tutorials (http://www.go4expert.com/articles/assembly-language-programming/)
-   -   How to Get CPU Vendor String, Using x86 Assembly Instruction (http://www.go4expert.com/articles/cpu-vendor-string-using-x86-assembly-t24794/)

lionaneesh 29Jan2011 21:31

How to Get CPU Vendor String, Using x86 Assembly Instruction
 
In this article I am going to demonstrate a basic use of low-level language to demonstrate how you can get your CPU Vendor string, and other hardware information using x86 assembly coding

Code:

section .data
        string db "The Vendor id string is 'XXXXXXXXXXXX'",0xA
section .text
global _start
_start:
        xor eax,eax
        cpuid
        mov edi,string
        mov [edi+25],ebx
        mov [edi+29],edx
        mov [edi+33],ecx
        mov eax,4
        mov ebx,1
        mov ecx,string
        mov edx,41
        int 0x80
        mov eax,1
        xor ebx,ebx
        int 0x80

Explanation



Section .data
It contains a basic String declaration (You should know this if you have some basic knowledge) with a 0x0A at the end that is the ascii code for a Line Feed or New Line...

The string contains 12 X's because these later will be overwritten by cpuid output..
Section .text
It contains a global declaration of _start label ..
_start : label
We xor the eax with eax(to make it zero) ….
cpuid (The main part of the code is this little instruction)..
cpuid Syntax

cpuid returns a number of things about our processor and this instruction can also be used to check if the processor is genuine or not...
cpuid acts (ouputs) differently on different eax values

Code:

Eax                    | Output   
                        |
0                      | The vendor string and the maximum input value supported
1                      | Processor type , model , stepping info etc etc...
2                      | Processor Cache information like no of threads , etc etc...
3                      | Processor serial number
4                      | Cache Configuration
5                      | Monitor information
0x80000000              | Extended vendor ID and supported levels
0x80000001              | Extended Processor type , family , model , etc etc...
0x80000002 – 0x80000004 | Extended Processor name string...

The cpiuid instruction outputs the data byte – by – byte in the following syntax :-
The data is contained in register byte-by-byte...
Code:

Register | Byte no
        |
EBX      | [byte 4]  [byte 3]  [byte 2]  [byte 1]
ECX        | [byte 8]  [byte 7]  [byte 6]  [byte 5]
EDX        | [byte 12]  [byte 11]  [byte 10]  [byte 9]

Fell free to feed these values and post the output here..
After cpuid
  • We first move the address of the string into edi...
  • Then we move the address pointed by the ebx register into string(25th byte) As seen in the syntax it contains the data bytes...Then we do the same in the next couple of instructions that should be self-explanatory..
  • Then we move 4 into eax and this is the syscall for write...
  • Rest couple of instructions are just passing the arguments for write instruction that should be basic if you know assembly
  • int 0x80 switch back to kernel mode
  • Then is the basic exit routine and we exit...
I hope it was easy to understand and thanks for reading.

lionaneesh 29Jan2011 23:29

Re: How to Get CPU Vendor String, Using x86 Assembly Instruction
 
Thanks for accepting my article.... and i hope less editing was required in this...

shabbir 30Jan2011 10:53

Re: How to Get CPU Vendor String, Using x86 Assembly Instruction
 
Quote:

Originally Posted by lionaneesh (Post 78511)
Thanks for accepting my article.... and i hope less editing was required in this...

Its decreasing all the time.

lionaneesh 30Jan2011 11:18

Re: How to Get CPU Vendor String, Using x86 Assembly Instruction
 
Quote:

Originally Posted by shabbir (Post 78527)
Its decreasing all the time.

Thanks...:):):)

alexsmth114 8Mar2011 12:14

Re: How to Get CPU Vendor String, Using x86 Assembly Instruction
 
Extremely useful post, should do a world of good to mot of the users out there!!..

lionaneesh 8Mar2011 14:33

Re: How to Get CPU Vendor String, Using x86 Assembly Instruction
 
Quote:

Originally Posted by alexsmth114 (Post 80376)
Extremely useful post, should do a world of good to mot of the users out there!!..

My Pleasure!!!


All times are GMT +5.5. The time now is 19:57.