I have a task to implement memcpy function in x86_64 assembler with this signature:
extern void* my_memcpy(void* dest, const void* src, uint32_t count);
I wrote it:
.intel_syntax noprefix
.text
.global my_memcpy
my_memcpy:
mov ecx, edx
shr rcx, 3
rep movsq
mov ecx, edx
and ecx, 7
rep movsb
- mov rax, rdi
ret
In my implementation there is a problem with the test when the value from src = “abcde” is copied to dest = “00000”. When comparing memcpy result and dest, it turns out that the result is “abcde” and dest is empty. And I seem to copy the result to rax before ret correctly. Moreover, if I don’t write mov rax, rdi, this test will pass and everything will work correctly. Could you please tell me how it works here and what the problem is?
You need to sign in to view this answers