I want to write programs in SysV ABI x86_64 assembly and so far I have passed the arguments in registers quite randomly.
But I just saw on this forum, that there is a standard for this. We must pass RDI, RSI, RDX and RCX (int that exact order).
Now I am asking myself two questions.
First, are not ESI and EDI supposed to be used only during operations on strings? What happens if I want to pass an integer as an argument and not a string?
Secondly, what if I need to pass a 32-bit argument and not a 64-bit argument? For example, if I want to create an identifier for the system call write
, I would write this:
;; void write(int fd, const void *buf, size_t count);
;; Inputs : ESI = offset string, EDX = number of characters to write, EBX = file descriptor
;; Outputs : <none>
;; Clobbers : <none>
write:
mov ecx, esi
mov eax, 4
int 0x80
ret
But with the standard, how can I move the values from 64-bit registers to 32-bit registers? Because I can't do that:
mov ecx, rdi ; impossible