How to Get CPU Vendor String, Using x86 Assembly Instruction

lionaneesh's Avatar author of How to Get CPU Vendor String, Using x86 Assembly Instruction
This is an article on How to Get CPU Vendor String, Using x86 Assembly Instruction in Assembly Language Programming (ALP) Tutorials.
Rated 5.00 By 1 users
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.
0
lionaneesh's Avatar, Join Date: Mar 2010
Invasive contributor
Thanks for accepting my article.... and i hope less editing was required in this...
Scripting like this
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by lionaneesh View Post
Thanks for accepting my article.... and i hope less editing was required in this...
Its decreasing all the time.
0
lionaneesh's Avatar, Join Date: Mar 2010
Invasive contributor
Quote:
Originally Posted by shabbir View Post
Its decreasing all the time.
Thanks...
Scripting like this
0
alexsmth114's Avatar, Join Date: Mar 2011
Go4Expert Member
Extremely useful post, should do a world of good to mot of the users out there!!..
0
lionaneesh's Avatar, Join Date: Mar 2010
Invasive contributor
Quote:
Originally Posted by alexsmth114 View Post
Extremely useful post, should do a world of good to mot of the users out there!!..
My Pleasure!!!