Skip to content

Instantly share code, notes, and snippets.

@snail5008
Created April 7, 2022 02:16
Show Gist options
  • Save snail5008/3d95325285a0907dc61c86425bf610e9 to your computer and use it in GitHub Desktop.
Save snail5008/3d95325285a0907dc61c86425bf610e9 to your computer and use it in GitHub Desktop.
A 'Hello World' program in GAS for linux x86_64
.global _start
.section .data
message: .ascii "Hello, World!\n"
len = . - message
.section .text
_start:
movq $1, %rax # sys_write
movq $1, %rdi # stdout
movq $message, %rsi # message
movq $len, %rdx # len of message
syscall # sys_write
movq $60, %rax # sys_exit
movq $0, %rdi # exit code 0
syscall # sys_exit
mkdir -p build/
mkdir -p build/part
as -c -o build/part/main.s.o main.s
ld -o build/a.out build/part/main.s.o
./build/a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment