Last active
April 3, 2017 15:48
-
-
Save nazares/9227fa2202c1dccf9da65cd306f53083 to your computer and use it in GitHub Desktop.
Hello World assembly macOS x86_64
This file contains 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
; nasm -f macho 32.asm | |
; ld -macosx_version_min 10.12 -o 32 32.o -lSystem | |
; ./32 | |
global _main | |
section .text | |
_main: | |
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 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
; NASM Intel Syntax for NASM assembly "Hello World!" | |
; nasm -f macho64 64.asm | |
; ld -macosx_version_min 10.12 -o 64 64.o -lSystem | |
;./64 | |
section .data | |
msg: db 'Hello World', 0xA | |
.len equ $-msg | |
section .text | |
global _main | |
_main: | |
mov eax, 0x2000004 | |
mov ebx, 1 | |
mov rsi, msg | |
mov rdx, msg.len | |
syscall | |
mov eax, 0x2000001 | |
mov ebx, 0 | |
syscall |
This file contains 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
// AT&T Syntax for GAS Assembly 'Hello World!' | |
# as -arch x86_64 -o 64gas.o 64gas.asm | |
# ld -macosx_version_min 10.12 -o 64gas 64gas.o -lSystem | |
# ./64gas | |
.data | |
HelloWorldString: | |
.ascii "Hello World!\n" | |
.text | |
.globl _main | |
_main: | |
# load all the arguments for write() | |
movl $0x2000004, %eax | |
movl $1, %ebx | |
movq HelloWorldString@GOTPCREL(%rip), %rsi | |
movq $100, %rdx | |
# raises software interrupt to call write() | |
syscall | |
# call exit() | |
movl $0x2000001, %eax | |
movl $0, %ebx | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment