Skip to content

Instantly share code, notes, and snippets.

@zliuva
Created July 8, 2011 14:56

Revisions

  1. softboysxp created this gist Jul 8, 2011.
    36 changes: 36 additions & 0 deletions cpuid.s
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    # cpuid.s
    # An x86_64 OS X port of the cpuid example found in Ch. 4 of Professional Assembly Language
    #
    # $ as -o cpuid.o cpuid.s
    # $ ld -o cpuid cpuid.o
    # $ ./cpuid
    # GenuineIntel
    # $

    .data
    output:
    .asciz "\0\0\0\0\0\0\0\0\0\0\0\0\n"
    len:
    .long len - output

    .text
    .globl start

    start:
    xor %rax, %rax
    cpuid

    leaq output(%rip), %rsi
    movl %ebx, (%esi)
    movl %edx, 4(%esi)
    movl %ecx, 8(%esi)

    movq len(%rip), %rdx
    # leaq output(%rip), %rsi # %rsi already contains address of output
    movq $0x1, %rdi # STDOUT
    movq $0x02000004, %rax # write
    syscall

    movq $0x0, %rdi
    movq $0x02000001, %rax # exit
    syscall