1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to Get CPU Vendor String, Using x86 Assembly Instruction

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

  1. lionaneesh

    lionaneesh New Member

    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

    section .data
            string db "The Vendor id string is 'XXXXXXXXXXXX'",0xA
    section .text
    global _start
            xor eax,eax
            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


    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

    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...
    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 New Member

    Thanks for accepting my article.... and i hope less editing was required in this...
    Scripting likes this.
  3. shabbir

    shabbir Administrator Staff Member

    Its decreasing all the time.
  4. lionaneesh

    lionaneesh New Member

    Scripting likes this.
  5. alexsmth114

    alexsmth114 New Member

    Extremely useful post, should do a world of good to mot of the users out there!!..
  6. lionaneesh

    lionaneesh New Member

    My Pleasure!!!

Share This Page