1

read() ラッパーを作成しようとしていますが、次のエラーが発生します。

エラー: 行 23 の 'asm' に不明なレジスタ名 '%%ebx' //(太字の行)

コードは次のとおりです。

#include <sys/syscall.h>
typedef unsigned int size_t;
typedef signed ssize_t;

extern int errno;

int main(void) {
    int fd = 0;
    char buf[128];
    size_t count = 128;
    my_read(fd, buf, count);

    return 0;
}

int my_read(int fd, void *buf, size_t count) {
    long ret;

    asm("pushl %%ebx\n\t" // Line 23
        "movl %%esi,%%ebx\n\t"
        "int $0x80\n\t"
        "popl %%ebx"
        : "=a" (ret)/* output */
        : "0"(SYS_read), "S"((long) fd), "c"((long) buf), "d"((long) count)/* input */
        : "%%ebx"/* clobbered register */
        );
    if (ret >= 0) {
        return (int) ret;
    }
    errno = -ret;
    return -1;
}

誰か助けてくれませんか?

4

1 に答える 1

5

%破壊されたラインから1 つドロップします。

: "%%ebx"/* clobbered register */
   ^

他のすべての行ではそのままにしておく必要があります。

編集

を削除extern int errno;して含めますerrno.h

于 2012-04-13T07:57:57.003 に答える