Skip to content

Instantly share code, notes, and snippets.

@qexat
Last active March 11, 2025 16:20
Show Gist options
  • Select an option

  • Save qexat/792b082c878a3f12e133739150668744 to your computer and use it in GitHub Desktop.

Select an option

Save qexat/792b082c878a3f12e133739150668744 to your computer and use it in GitHub Desktop.
least portable C hello world program
// only works on Compiler Explorer with x86-64 gcc
// gcc hello.c -o hello && ./hello
extern int(puts)(char const *);
char static *message = "Hello World!\n";
__attribute__((used)) void f(void)
{
puts(message);
}
int main(void)
{
asm("mov $0x402004, %edi");
asm("call 0x401030");
asm("xor %eax, %eax");
asm("pop %rbp");
asm("ret");
while (1)
{
f();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment