← Back to context

Comment by im3w1l

16 days ago

Or just

  int main(void) {
    asm volatile("syscall" : : "a"(1), "d"(14), "D"(1), "S"("hello world!\n"));
    return 0;
  }

Though the clobber list is weak spot, I don't know exactly what it should have in this case.

You want:

    long ax;
    asm volatile("syscall" : "=a"(ax) : "0"(1), "D"(1), "S"("hello world!\n"), "d"(14));

You can also say:

    long ax = 1;
    asm volatile("syscall" : "+a"(ax) : "D"(1), "S"("hello world!\n"), "d"(14));

https://justine.lol/dox/rmsiface.txt

  • Got some sleep and took a second look. You actually want:

        long ax = 1;
        asm volatile("syscall" : "+a"(ax) : "D"(1), "S"("hello world!\n"), "d"(14) : "rcx", "r11");
    

    Sorry folks! Note also this only works on Linux. On BSDs for example, even if you change the magic number, BSDs may clobber all the call-clobbered registers. So with those OSes it's usually simplest to write an assembly stub like this:

        my_write:
          mov $4,%eax
          syscall
          ret