Skip to content

Instantly share code, notes, and snippets.

@dnicolson
Created November 27, 2015 11:14
Show Gist options
  • Save dnicolson/6f291af7ab9d93248cfa to your computer and use it in GitHub Desktop.
Save dnicolson/6f291af7ab9d93248cfa to your computer and use it in GitHub Desktop.
An example of making a syscall in assembly on OS X
; nasm -f macho64 mkdir.asm && ld -o mkdir mkdir.o && ./mkdir
%define SYSCALL_MKDIR 0x2000088
%define SYSCALL_EXIT 0x2000001
global start
section .text
start:
call mkdir
call exit
ret
mkdir:
mov rax, SYSCALL_MKDIR
mov rdi, directory
mov rsi, 0x1ED
syscall
exit:
mov rax, SYSCALL_EXIT
mov rdi, 0
syscall
section .data
directory: db 'tmp', 0
@y4rr
Copy link

y4rr commented Feb 17, 2021

nasm -f macho64 mkdir.asm && ld -e start -static -o mkdir mkdir.o

correct way to build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment