Inline Assembler für Wrapper-Funktion funktioniert aus irgendeinem Grund nicht

Ich versuche, eine Wrapper-Funktion für den Systemaufruf read () mit asm volatile zu schreiben, aber das funktioniert nicht, da die res ihren Wert nicht ändert.

Hier ist der Code:

<code>ssize_t my_read(int fd, void *buf, size_t count)

{

      ssize_t res;

      __asm__ volatile(
        "int $0x80"        /* make the request to the OS */
        : "=a" (res),       /* return result in eax ("a") */
          "+b" (fd),     /* pass arg1 in ebx ("b") */
          "+c" (buf),     /* pass arg2 in ecx ("c") */
          "+d" (count)      /* pass arg3 in edx ("d") */
        : "a"  (5)          /* passing the system call for read to %eax , with call number 5  */
        : "memory", "cc"); /* announce to the compiler that the memory and condition codes have been modified */

      /* The operating system will return a negative value on error;
       * wrappers return -1 on error and set the errno global variable */

      if (-125 <= res && res < 0)
      {
        errno = -res;
        res   = -1;
      }

      return res;

}
</code>

und hier istint main () :

<code> int main() {
     int fd = 432423;
     char buf[128];
     size_t count = 128;
     my_read(fd, buf, count);

     return 0;
 }
</code>

Mache ich etwas falsch ? Vielleicht liegt es an dervolatile ?

Ich habe versucht, den Code zu debuggen, und wenn Eclipse eingehtmy_read(fd, buf, count); und kommt zur Linie__asm__ volatile( immy_read scheitert es und geht hineinif (-125 <= res && res < 0) ...

EDIT:

<code>ssize_t my_read(int fd, void *buf, size_t count)

{

      ssize_t res;

      __asm__ volatile(
        "int $0x80"        /* make the request to the OS */
        : "=a" (res)       /* return result in eax ("a") */

        : "a"  (5) ,      /* passing the system call for read to %eax , with call number 5  */
          "b" (fd),     /* pass arg1 in ebx ("b") */
          "c" (buf),     /* pass arg2 in ecx ("c") */
          "d" (count)      /* pass arg3 in edx ("d") */

        : "memory", "cc"); /* announce to the compiler that the memory and condition codes have been modified */

      /* The operating system will return a negative value on error;
       * wrappers return -1 on error and set the errno global variable */

      if (-125 <= res && res < 0)
      {
        errno = -res;
        res   = -1;
      }

      return res;

}
</code>

und Haupt:

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

     return 0;
 }
</code>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage