Skip to content

Instantly share code, notes, and snippets.

@zliuva
Created July 9, 2011 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zliuva/1073421 to your computer and use it in GitHub Desktop.
Save zliuva/1073421 to your computer and use it in GitHub Desktop.
calling libc functions on OS X x64
# cpuid2.s
# calling libc functions on OS X x64
#
# $ as -g -o cpuid2.o cpuid2.s
# $ ld -o cpuid2 -lc cpuid2.o
# $ ./cpuid2
# Vendor ID: GenuineIntel
# $
.data
_output:
.asciz "Vendor ID: %s\n"
.lcomm _vendor, 12
.text
.globl start
start:
xorq %rbp, %rbp
pushq %rbp
xorq %rax, %rax
cpuid
leaq _vendor(%rip), %rsi
movl %ebx, (%esi)
movl %edx, 4(%esi)
movl %ecx, 8(%esi)
# leaq _vendor(%rip), %rsi
leaq _output(%rip), %rdi
xorq %rax, %rax
callq _printf
xorq %rdi, %rdi
callq _exit
hlt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment