Cannot force 64-bit registers in GCC inline assembly

I try to do some things with the GCC Inline Assembly, in this case I will do Syscall, but I want to force the use of 64-bit registers (rax, rdi, rsi, ...) instead of 32-bit (eax, edi, ...), but I tried many ways, and nothing.

void syscall(uint64_t arg1, uint64_t arg2) {
   // arg1 -> rax        arg2 -> rdi
   __asm__("syscall" : : "a" (arg1), "D" (arg2));
}

When I compile, I get:

mov eax, 60
syscall

I have a function, so "edi" is obtained from the arguments, but as you can see it is "eax", I want to use rax.

How can I force 64-bit registers instead of 32-bit?

+4
source share
1 answer

This actually sets the RAX register to 60:

mov eax, 60

EAX 32- 64- . AH AL, .

RAX, - :

static inline __attribute__ ((always_inline)) void
syscall(uint64_t arg1, uint64_t arg2)
{
   __asm__("mov rax, %0; syscall" : : "i" (arg1), "D" (arg2) : "rax");
}

, gas 32- .

+8

Source: https://habr.com/ru/post/1681731/


All Articles