Have a look at example 4 (won't win a prize for portability):
#include <syscall.h>
void syscall1(int num, int arg1)
{
asm("int\t$0x80\n\t":
/* output */ :
/* input */ "a"(num), "b"(arg1)
/* clobbered */ );
}
void syscall3(int num, int arg1, int arg2, int arg3)
{
asm("int\t$0x80\n\t" :
/* output */ :
/* input */ "a"(num), "b"(arg1), "c"(arg2), "d"(arg3)
/* clobbered */ );
}
char str[] = "Hello, world!\n";
int _start()
{
syscall3(SYS_write, 0, (int) str, sizeof(str)-1);
syscall1(SYS_exit, 0);
}
Edit: as pointed out by Zan Lynx below, the first argument to sys_write is the file descriptor. Thus this code does the uncommon thing of writing "Hello, world!\n"
to stdin (fd 0) instead of stdout (fd 1).