I was trying to implement memmove from C into x86 assembly so I wrote:
start:
movb source(%eax), %cl
movb %cl, destination(%eax)
inc %eax
cmp num, %eax
jne start
end:
But this is wrong, why? according to: http://www.cplusplus.com/reference/cstring/memmove/
Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap.
which my code doesn't support.
How can I fix this without using stack? Note: we can assume that immediately after source destination comes in memory and that num (number of bytes to copy) is far and can't be touched by wrong.