1 ! _memmove
() Author
: Kees J. Bot
3 .sect .text; .sect .rom; .sect .data; .sect .bss
5 ! void
*_memmove
(void
*s1
, const void
*s2
, size_t n
)
6 ! Copy
a chunk of memory. Handle overlap.
9 .define __memmove, __memcpy
16 mov edi
, 8(ebp
) ! String s1
17 mov esi
, 12(ebp
) ! String s2
18 mov ecx
, 16(ebp
) ! Length
22 jb downwards
! if
(s2
- s1
) < n then copy downwards
24 cld
! Clear direction bit
: upwards
26 jb upbyte
! Don
't bother being smart with short arrays
30 jnz upbyte ! Bit 0 set, use byte copy
32 jnz upword ! Bit 1 set, use word copy
33 uplword:shrd eax, ecx, 2 ! Save low 2 bits of ecx in eax
36 movs ! Copy longwords.
37 shld ecx, eax, 2 ! Restore excess count
41 adc ecx, ecx ! One more byte?
44 done: mov eax, 8(ebp) ! Absolutely noone cares about this value
50 ! Handle bad overlap by copying downwards, don't bother to do word copies.
52 std ! Set direction bit
: downwards
53 lea esi
, -1(esi
)(ecx
*1)
54 lea edi
, -1(edi
)(ecx
*1)