0

wikibooks (Scroll down to "Via interrupt") Have an Assembly x86 wiki which shows us registers mapping for system calls, and we can see that eax is the syscall numeric value, and ebx is the first parameter, etc.

Do we always need to use this order for syscalls? and where can I find the exact page but for x86_64 assembly (which have different registers)?

mov rax, 1        ; write(
mov rdi, 1        ;   STDOUT_FILENO,
mov rsi, msg      ;   "Hello, world!\n",
mov rdx, msg_len  ;   sizeof("Hello, world!\n")
syscall           ; );
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Dudu Faruk
  • 43
  • 1
  • 5
  • It doesn't matter which order you set registers, only that they have the right contents when the `syscall` instruction executes. But I think you just mean the mapping from parameter order to registers in the calling convention / ABI. – Peter Cordes Sep 06 '20 at 20:22
  • @PeterCordes I wanted to ask if the order of the registers in a syscall are matter – Dudu Faruk Sep 06 '20 at 20:25
  • 1
    The duplicates tell you exactly what matters: that each argument is placed in the corresponding register. In what order you assign the arguments doesn't matter as long each argument ends in the right register. Note that it never (except under very specific circumstances you are unlikely to ever encounter) matters what order you assign to registers. Nobody can observe that order anyway. – fuz Sep 06 '20 at 20:33
  • 1
    @fuz Thank you. One more question, how do I know if a register is placed in the right argument and vice versa? – Dudu Faruk Sep 06 '20 at 20:38
  • Check the manual for the system call. The registers are assigned to the arguments in the order given in the manual page from left to right. – fuz Sep 06 '20 at 20:39
  • @fuz Good to know. Thank you – Dudu Faruk Sep 06 '20 at 20:41
  • You can always check with `strace ./a.out` to decode your syscall args. – Peter Cordes Sep 07 '20 at 12:09

0 Answers0