Why is the exitcode given in this paragraph of Linux x64 syscall _ _ NR_exit wrong?

this is a piece of code in C that calls ASM directly:

  http://blog.rchapman.org/post.

Dec.01,2021

problem solved. The problem is that my failure to declare rax in the fourth domain of asm () causes changed, to cause 0 to be stored directly in rax .

the correct code is as follows:

void _start() {
    int ret = 2;
    asm(
        "mov $60, %%rax;"  // __NR_exit
        "mov %0, %%edi;"   // param 1
        "syscall"
        :
        : "r"(ret)
        : "rax", "rdi"
    );
}
Menu