Created
September 10, 2015 20:12
-
-
Save carloscarcamo/6833d19b726af698e62b to your computer and use it in GitHub Desktop.
Hello world in GNU Assembler (GAS)
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
# ------------------------------------------------------------- | |
# | |
# Using Linux System calls for 64-bit | |
# to run: | |
# gcc -c hello.s && ld hello.o && ./a.out | |
# o | |
# gcc -nostdlib hello.s && ./a.out | |
# | |
# -------------------------------------------------------------- | |
.global _start | |
.text | |
_start: | |
# write (1, msj, 13) | |
mov $1, %rax # system call 1 is write | |
mov $1, %rdi # file handler 1 is stdout | |
mov $message, %rsi # address of string to output | |
mov $13, %rdx # number of bytes | |
syscall | |
# exit(0) | |
mov $60, %rax # system call 60 is exit | |
xor %rdi, %rdi # we want to return code 0 | |
syscall | |
message: | |
.ascii "Hello, world\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gcc -nostdlib -nostartfiles -nodefaultlibs -static -c hello.s
ld -o hello -static hello.o
strip hello