Skip to content

Instantly share code, notes, and snippets.

@zliuva
Created July 8, 2011 14:56
Show Gist options
  • Save zliuva/1072017 to your computer and use it in GitHub Desktop.
Save zliuva/1072017 to your computer and use it in GitHub Desktop.
An x86_64 OS X port of the cpuid example found in Ch. 4 of Professional Assembly
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment