As a simple example, I wanted to invoke a syscall with rdi=0 and rax=param.
My first attempt did not work:
Code:
__asm__ ("syscall\n"::"rdi"(0), "rax"(param): "rcx", "r11");
Through trial and error, this eventually worked:
Code:
_asm__ ("syscall\n"::"D"(0), "a"(param): "rcx", "r11");
In the
GCC user manual it lists 'a', 'b', 'c', 'd', 'S', 'D' as refering to rax, rbx, rcx, rdi, rsi, rdi, But, it doesn't make it clear what to do if I wanted to use r8-r15?
I found
this documentation on local register variables that suggests you could do:
Code:
register unsigned long long int syscall_num asm ("rdi") = 0;
register unsigned long long int r_param asm ("rax") = param;
__asm__ ("syscall\n"::"r"(syscall_num), "r"(r_param): "rcx", "r11");
Does anybody have any tips on working with inline assembly they use?