Author Topic: cpuid and serial number?  (Read 10153 times)

Offline flatcircuit

  • Jr. Member
  • *
  • Posts: 4
cpuid and serial number?
« on: October 10, 2015, 11:33:16 PM »
I understand that cpuid retreives the "class" of your cpu.

Is the serial number that is printed on a cpu also hardcoded into the cpu usually? If yes, how would I retrieve it with nasm?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: cpuid and serial number?
« Reply #1 on: October 17, 2015, 05:04:24 AM »
https://en.wikipedia.org/wiki/CPUID

This seems to confirm my recollection that we got all paranoid about the serial number, and that it was generally not available. If it is, eax = 3 - number in edx:ecx, ebx:eax, or ebx only... if it's enabled in BIOS.

Here's a cpuid I've got handy...
Code: [Select]
; nasm -f elf32 cpuname.asm
; ld -o cpuname cpuname.o -m elf_i386

global _start

section .bss
    namestring resb 49

section .text
_start:

    mov eax, 80000000h
    cpuid
    cmp eax, 80000004h
    jb exit
   
    mov edi, namestring

    mov eax, 80000002h
    cpuid
    call savestring

    mov eax, 80000003h
    cpuid
    call savestring

    mov eax, 80000004h
    cpuid
    call savestring
    mov al, 10
    stosb

    mov ecx, namestring
    mov edx, 49
    mov ebx, 1
    mov eax, 4
    int 80h

exit:
    mov eax, 1
    int 80h
;----------------

;----------------
savestring:
    stosd
    mov eax, ebx
    stosd
    mov eax, ecx
    stosd
    mov eax, edx
    stosd
    ret
;----------------


Not quite what you're looking for...

Best,
Frank