Last active
October 16, 2023 07:03
-
-
Save sulincix/b30a833ab70fa37fafeea45d5ce3fb10 to your computer and use it in GitHub Desktop.
Hello World without libc
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
// Compile with: | |
// gcc -o main main.c -nostdlib -O0 | |
int print(char* msg, int len){ | |
/* | |
rax = 1 (write) | |
rdi = 1 (stdout) | |
rsi = message | |
rdx = length | |
syscall | |
*/ | |
register char* arg2 asm("rsi") = msg; | |
register int arg3 asm("rdx") = len; | |
__asm__("mov $1, %rax; mov $1, %rdi; syscall;"); | |
return 0; | |
} | |
int _start(int argc, char** argv){ | |
print("Hello World\n", 14); | |
/* | |
rax = 60 (exit) | |
rdi = 0 | |
syscall | |
*/ | |
__asm__("mov $60,%rax; mov $0,%rdi; syscall"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment