linux 64bitを想定
#include<stdio.h>
int main(void){
printf("Hello, world!\n");
return 0;
}
#include <unistd.h>
int main(void){
write(1,"Hello, world!\n",14);
return 0;
}
int main(void)
{
const char mes[] = "hello, world\n";
asm("movq %0, %%rdx" :: "r"(sizeof(mes)) );
asm("movq %0, %%rsi" :: "r"(mes) );
asm("movq $1, %%rdi" ::);
asm("movl $1, %%eax" ::);
asm("syscall");
}
gcc -O3 -static -fomit-frame-pointer -nostartfiles -fno-stack-protector hello.c
void _start(void){
const char mes[] = "hello, world\n";
asm("movq %0, %%rdx" :: "r"(sizeof(mes)) );
asm("movq %0, %%rsi" :: "r"(mes) );
asm("movq $1, %%rdi" ::); /* stdout */
asm("movl $1, %%eax" ::); /* write */
asm("syscall");
asm("movq $0, %%rdi" ::);
asm("movl $0x3c, %%eax" ::); /* _exit */
asm("syscall");
}