Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can get the CPU unique ID?

How can get the CPU unique ID?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangyiming
    wrote on last edited by
    #1

    Thanks

    M 1 Reply Last reply
    0
    • W wangyiming

      Thanks

      M Offline
      M Offline
      moliate
      wrote on last edited by
      #2

      Assuming the processor supports unique serial number:

      #define cpuid __asm __emit 0fh __asm __emit 0a2h
      UINT PSN, ID1, ID2, ID3;

      __asm
      {
      mov eax, 01H
      cpuid
      mov PSN, edx
      }

      if (PSN&0x20000 0x40000) //Check bit 18 if serial number is available
      {
      __asm
      {
      mov eax, 01H
      cpuid
      mov ID1, eax
      mov eax, 03H
      cpuid
      mov ID2, edx
      mov ID3, ecx
      }
      }
      else
      {//Processor does not support unique ID
      }

      If everything works out ID1, ID2, ID3 should contain the unique 96 bit ID. I havn´t tested the code since I don´t have a PIII, but I hope it works... More info on cpuid here (pdf). Hope this helps /moliate

      W 1 Reply Last reply
      0
      • M moliate

        Assuming the processor supports unique serial number:

        #define cpuid __asm __emit 0fh __asm __emit 0a2h
        UINT PSN, ID1, ID2, ID3;

        __asm
        {
        mov eax, 01H
        cpuid
        mov PSN, edx
        }

        if (PSN&0x20000 0x40000) //Check bit 18 if serial number is available
        {
        __asm
        {
        mov eax, 01H
        cpuid
        mov ID1, eax
        mov eax, 03H
        cpuid
        mov ID2, edx
        mov ID3, ecx
        }
        }
        else
        {//Processor does not support unique ID
        }

        If everything works out ID1, ID2, ID3 should contain the unique 96 bit ID. I havn´t tested the code since I don´t have a PIII, but I hope it works... More info on cpuid here (pdf). Hope this helps /moliate

        W Offline
        W Offline
        wangyiming
        wrote on last edited by
        #3

        Thank you very much

        M 1 Reply Last reply
        0
        • W wangyiming

          Thank you very much

          M Offline
          M Offline
          moliate
          wrote on last edited by
          #4

          There was a litte bug in the sample program... :-O Bit 18 is 0x40000, not 0x20000. If you havn't discovered it yourself I think I should save you some trouble.... /moliate

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups