Skip to content

Instantly share code, notes, and snippets.

@carloscarcamo
Created September 10, 2015 20:12
Show Gist options
  • Save carloscarcamo/6833d19b726af698e62b to your computer and use it in GitHub Desktop.
Save carloscarcamo/6833d19b726af698e62b to your computer and use it in GitHub Desktop.
Hello world in GNU Assembler (GAS)
# -------------------------------------------------------------
#
# 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"
@ii64
Copy link

ii64 commented Nov 12, 2021

gcc -nostdlib -nostartfiles -nodefaultlibs -static -c hello.s
ld -o hello -static hello.o
strip hello

image

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