Skip to content

Instantly share code, notes, and snippets.

@kellegous
Last active August 29, 2015 14:05
Show Gist options
  • Save kellegous/4b5ba8117218d1e7f03e to your computer and use it in GitHub Desktop.
Save kellegous/4b5ba8117218d1e7f03e to your computer and use it in GitHub Desktop.
// gcc -Wall -nostdlib -o hello hello.c
void _start() {
const char msg[] = "Hello World\n";
const unsigned long len = sizeof(msg);
asm volatile
(
// write(STDOUT_FILENO, msg, len)
"mov $1, %%rdi\n\t" // stdout is 1
"mov %0, %%rsi\n\t" // addr of msg
"mov %1, %%rdx\n\t" // len of msg
"mov $1, %%rax\n\t" // write is syscall 1
"syscall\n\t"
// exit(0)
"xor %%rdi, %%rdi\n\t" // zero rdi
"mov $60, %%rax\n\t" // exit is syscall 60
"syscall"
:
: "g"(msg), "g"(len)
: "%rdi", "%rsi", "%rdx", "%rcx", "%r11"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment