Created
October 27, 2019 07:19
-
-
Save osnr/66fb5e6ec87981e60d34248171c65802 to your computer and use it in GitHub Desktop.
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
// should work with tcc 0.9.27 from: https://bellard.org/tcc/ which I | |
// think merges minimal Darwin support from https://github.com/andreiw/tinycc | |
// (I think only `-run` works; it can't output a Mach-O executable?) | |
// | |
// but the header and libc situation on macOS for non-GCC/clang is | |
// such an incredible mess -- I did kinda get it working, but it's | |
// more fun to just write something that calls directly into the OS & | |
// has no dependencies (: | |
// | |
// $ tcc -nostdlib -nostdinc -run minimal-osx-tcc-hello.c | |
// Hello. | |
int main() { | |
char str[] = "Hello.\n"; | |
asm("mov $0x2000004, %%rax;" // write syscall | |
"mov $1, %%rdi;" // stdout fd | |
"mov %0, %%rsi;" // str | |
"mov %1, %%rdx;" // str length (w/o null terminator) | |
"syscall" | |
: | |
: "r" (str), "g" (sizeof str - 1) | |
: "rax", "rdi", "rsi", "rdx"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment