Created
December 31, 2016 21:38
-
-
Save vicapow/a55f78e53b5876e0d86fbffb65094803 to your computer and use it in GitHub Desktop.
'Hello world!' in x86_64 assembly without using any external libs.
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
## 'Hello world!' in x86_64 AT&T gas assembly in OS X. | |
## To assemble $> as -arch x86_64 example3-helloworld.s -o example3-helloworld.o | |
## To link: $> ld -arch x86_64 example3-helloworld.o -e _main -o example3-helloworld -lSystem | |
.section __TEXT,__text | |
.macosx_version_min 10, 12 | |
.globl _main | |
_main: | |
movq $0x2000004, %rax # write (system call $4 with $0x2000000 offset) | |
movq $1, %rdi # write to stdout (fid 1) | |
leaq L_.str(%rip), %rsi # set the register address of the start of the string | |
movq $13, %rdx # print out the first 12 characters of the string. | |
syscall # take the shot. | |
movq $0x2000001, %rax # exit (system call $1 with $0x2000000 offset) | |
movq $0, %rdi # use exit code 0. | |
syscall # take the shot. | |
.section __TEXT,__cstring,cstring_literals | |
L_.str: ## @.str | |
.asciz "Hello World!\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment