1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Get CPU Vendor String, Using x86 Assembly Instruction

Discussion in 'Assembly Language Programming (ALP)' started by lionaneesh, Jan 29, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    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.
     
  2. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Thanks for accepting my article.... and i hope less editing was required in this...
     
    Scripting likes this.
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Its decreasing all the time.
     
  4. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Thanks...:):):)
     
    Scripting likes this.
  5. alexsmth114

    alexsmth114 New Member

    Joined:
    Mar 7, 2011
    Messages:
    19
    Likes Received:
    1
    Trophy Points:
    0
    Extremely useful post, should do a world of good to mot of the users out there!!..
     
  6. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    My Pleasure!!!
     

Share This Page