section .text
global memcpy
memcpy:
mov rcx, rdx
mov rax, rdi
rep movsb
ret
global memset
memset:
push rdi
mov rax, rsi
rep stosb
pop rax
global memmove
memmove:
cmp rdi, rsi
ja .copy_backwards
jmp .done
.copy_backwards:
lea rdi, [rdi+rcx-1]
lea rsi, [rsi+rcx-1]
std
cld
.done:
global memcmp
memcmp:
repe cmpsb
je .equal
mov al, byte [rdi-1]
sub al, byte [rsi-1]
movsx rax, al
.equal:
xor eax, eax