This code print "Hello World!" and exit without C library. ref.(Programmer's self-cultivation -- Link, load, and library)
I do not understand why there is "%%" in front of "rax" in print(), but "%" in front of "rax" in exit(). I have tried to add another "%" in front of "rax" in exit(), and I get the error message:
TinyHelloWorld.c:14: Error: bad register name `%%rbx'
TinyHelloWorld.c:15: Error: bad register name `%%rax'
WRITE has a system call number of 4 and EXIT is 1, I have no idea what is the difference about the use of "rax"?
char *str="Hello world!\n";
void print()
{
asm("movq $13,%%rdx \n\t"
"movq %0,%%rcx \n\t"
"movq $0,%%rbx \n\t"
"movq $4,%%rax \n\t"
"int $0x80 \n\t"
::"r"(str):"edx","ecx","ebx");
}
void exit()
{
asm("movq $42,%rbx \n\t"
"movq $1,%rax \n\t"
"int $0x80 \n\t");
}
void nomain()
{
print();
exit();
}