0

I can't run the following C code:

#include <sys/syscall.h>
#include <sys/types.h>

#define NULL ((void*)0)

int syscall3 (int code, int arg1, char* arg2, int arg3);
int syscall1 (int code, int arg);


int _start() {

    char ptr[14] = "Hello sysprog";
    syscall3(SYS_write, 0, ptr, 14);
    syscall1(SYS_exit, 0);
    return 0;
}

int syscall3 (int code, int arg1, char* arg2, int arg3) {
    asm volatile("int $0x80": "=a" (code) : "a" (code), "b" (arg1), "c" (arg2), "d" (arg3));
    return code;
}

int syscall1 (int code, int arg) {
    asm volatile("int $0x80": "=a" (code) : "a" (code));
    return code;
}

I tried to compile using -nostdlib an -nostartfiles gcc options, but it doesn't work.

What I have to do to run that code?

shogitai
  • 1,823
  • 1
  • 23
  • 50

0 Answers0