Skip to content

Instantly share code, notes, and snippets.

@sulincix
Last active October 16, 2023 07:03
Show Gist options
  • Save sulincix/b30a833ab70fa37fafeea45d5ce3fb10 to your computer and use it in GitHub Desktop.
Save sulincix/b30a833ab70fa37fafeea45d5ce3fb10 to your computer and use it in GitHub Desktop.
Hello World without libc
// 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