source: trunk/minix/lib/i86/string/_memmove.s@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.0 KB
Line 
1! _memmove() Author: Kees J. Bot
2! 27 Jan 1994
3.sect .text; .sect .rom; .sect .data; .sect .bss
4
5! void *_memmove(void *s1, const void *s2, size_t n)
6! Copy a chunk of memory. Handle overlap.
7!
8.sect .text
9.define __memmove, __memcpy
10__memmove:
11 push bp
12 mov bp, sp
13 push si
14 push di
15 mov di, 4(bp) ! String s1
16 mov si, 6(bp) ! String s2
17 mov cx, 8(bp) ! Length
18 mov ax, di
19 sub ax, si
20 cmp ax, cx
21 jb downwards ! if (s2 - s1) < n then copy downwards
22__memcpy:
23 cld ! Clear direction bit: upwards
24 cmp cx, #16
25 jb upbyte ! Don't bother being smart with short arrays
26 mov ax, si
27 or ax, di
28 testb al, #1
29 jnz upbyte ! Bit 0 set, use byte copy
30upword: shr cx, #1
31 rep movs ! Copy words
32 adc cx, cx ! One more byte?
33upbyte:
34 rep movsb ! Copy bytes
35done: mov ax, 4(bp) ! Absolutely noone cares about this value
36 pop di
37 pop si
38 pop bp
39 ret
40
41! Handle bad overlap by copying downwards, don't bother to do word copies.
42downwards:
43 std ! Set direction bit: downwards
44 add si, cx
45 dec si
46 add di, cx
47 dec di
48 rep movsb ! Copy bytes
49 cld
50 jmp done
Note: See TracBrowser for help on using the repository browser.