Last active
August 29, 2015 14:05
-
-
Save kellegous/4b5ba8117218d1e7f03e to your computer and use it in GitHub Desktop.
This file contains 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
// 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