- NASM Manual - for the syntax
- What are the calling conventions for UNIX & Linux system calls on x86-64 - comparison
- AMD64 ABI reference - A.2.1 - for the actual x86_64 calling convention
- X86 calling conventions - moar calling conventions
- Mac OS X syscalls reference
-
-
Save ericandrewlewis/8bb8d29ebf65c325ed76 to your computer and use it in GitHub Desktop.
NASM Hello World for x86 and x86_64 Intel Mac OS X(get yourself an updated nasm with brew)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32 | |
global start | |
section .text | |
start: | |
push dword msg.len | |
push dword msg | |
push dword 1 | |
mov eax, 4 | |
sub esp, 4 | |
int 0x80 | |
add esp, 16 | |
push dword 0 | |
mov eax, 1 | |
sub esp, 12 | |
int 0x80 | |
section .data | |
msg: db "Hello, world!", 10 | |
.len: equ $ - msg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; To convert this assembly code to an executable file (machine language) and execute it, run: | |
; /usr/local/bin/nasm -f macho64 64.asm && ld -macosx_version_min 10.7.0 -lSystem -o 64 64.o && ./64 | |
global start | |
section .text | |
start: | |
mov rax, 0x2000004 ; write | |
mov rdi, 1 ; stdout | |
lea rsi, [rel msg] | |
mov rdx, msg.len | |
syscall | |
mov rax, 0x2000001 ; exit | |
mov rdi, 0 | |
syscall | |
; The .data section is for storing and naming constants. | |
section .data | |
msg: db "Hello, world!", 10 | |
; Length of `msg`. `$` refers to the address of this constant, so `$ - msg` is the length of message | |
.len: equ $ - msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment