I am using nasm on Ubuntu 16.04, and I'm currently trying to recode the C memmove()
function.
Here is my code :
BITS 64
global memmove
memmove:
push rbp
mov rbp, rsp
xor rcx, rcx
while:
cmp rcx, rdx
je end
mov r10b, byte [rsi + rcx]
mov byte [rdi + rcx], r10b
inc rcx
jmp while
end:
mov rax, rdi
leave
ret
I'm calling it this way :
char *str = strdup("Salutation");
printf("%s, %s\n", (char *)memmove(str + 3, str, 5), str);
Expected output is :
Saluton, SalSaluton
But I get :
SalSaon, SalSalSaon
For some reasons, when I get to the fourth character, it goes back to the begining of my string rsi
. My question is why? What am I doing wrong?
PS : The same problem happens every three characters, like if it could not go futher, and had to go back to the first one.
Thanks in advance.