通过内嵌汇编来调用系统调用,封装实现write。write系统调用号为4.

$ grep -i write /usr/include/asm/unistd_32.h #define __NR_write 4

/*test_write.c*/
#include<stdio.h>

int my_write(int fd, const void *buf, size_t count)
{
        __asm__ __volatile__(
                        "movl $4, %%eax;"
                        "int  $0x80"
                        :
                        :"b"(fd),"c"(buf),"d"(count)
                        );

        return 0;
}

int main()
{
        my_write(1,"abc\n",4);
        return 0;
}