In reading - When "Programmer's self-cultivation loading link with the library," the fourth chapter statically linked == == == 4.6.2 == minimum program, found that it is based on the program linux32-bit systems, not in 64 the bit systems to compile and run.
The correct 64-bit programs should be
Code
char *str = "Hello world!\n";
void print(){
asm("movq $13,%%rdx \n\t"
"movq %0,%%rsi \n\t"
"movq $0,%%rdi \n\t"
"movq $1,%%rax \n\t"
"syscall \n\t"
::"r"(str) : "rdx", "rsi", "rdi");
}
void exit(){
asm("movq $42,%rdi \n\t"
"movq $60,%rax \n\t"
"syscall \n\t");
}
void nomain(){
print();
exit();
}
operation result
the reason
linux compilation system 64-bit and 32-bit system call compiled mainly in the following ways:
- Call number of different systems, such as the x86 sys_write is 4, sys_exit is 1; while the x86_64
sys_write is 1, sys_exit 60. linux system call number is actually defined in /usr/include/asm/unistd_32.h and /usr/include/asm/unistd_64.h in.- System call different registers used, x86_64 eax using the corresponding rax delivery system call number, but> x86_64 were used rdi / rsi / rdx passed the first three parameters, instead of x86 ebx / ecx / edx.
- Use the system call "syscall" instead of "int 80"