Implemented RFE #1914256
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 26 Dec 2008 10:23:35 +0000 (10:23 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 26 Dec 2008 10:23:35 +0000 (10:23 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5300 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/lib/Makefile.in
device/lib/z80/Makefile.in
device/lib/z80/memmove.s [new file with mode: 0644]

index ece91a9b71bf806776d4a94134343cafd831b3fc..d53ff3881d4c7aed18f8e92ed08068372cfa611a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-26 Philipp Klaus Krause <pkk AT spth.de>
+       * device/lib/z80/Makefile.in,
+         device/lib/Makefile.in,
+         device/lib/z80/memmove.s: Implemented RFE #1914256
+
 2008-12-26 Philipp Klaus Krause <pkk AT spth.de>
 
        * src/z80/peeph-z80.def: fixed a bug in peephole 0zf
index fa743b6dfee29b061199658164bebb9cd4429aa2..94d3214feb782bfa29966c5b7f1f3cab9d871b76 100644 (file)
@@ -124,7 +124,7 @@ Z80SOURCES =        \
                _strcspn.c _strlen.c _strncat.c _strncmp.c \
                _strncpy.c _strpbrk.c _strrchr.c _strspn.c \
                _strstr.c _strtok.c \
-               _memcmp.c _memcpy.c _memmove.c _memset.c \
+               _memcmp.c _memcpy.c _memset.c \
                _calloc.c _malloc.c _realloc.c _free.c \
                printf_large.c sprintf.c vprintf.c puts.c gets.c \
                assert.c time.c \
index 31b5c64f7c2a8ec1de73e5624a22a3506415650f..45d8a86d70d1f542bb18ee157f163145392cbfab 100644 (file)
@@ -8,7 +8,7 @@ TOPDIR = ../../..
 SCC = $(TOPDIR)/bin/sdcc -mz80
 SAS = $(TOPDIR)/bin/as-z80
 
-OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o
+OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o memmove.o
 
 LIB = z80.lib
 CC = $(SCC)
diff --git a/device/lib/z80/memmove.s b/device/lib/z80/memmove.s
new file mode 100644 (file)
index 0000000..55462ef
--- /dev/null
@@ -0,0 +1,44 @@
+        .area   _CODE
+
+       .globl _memmove
+
+; The Z80 has the ldir and lddr instructions, which are perfect for implementing memmove().
+
+_memmove:
+       push    ix
+       ld      ix,#0
+       add     ix,sp
+       ld      c, 8(ix)
+       ld      b, 9(ix)
+       ld      a, c
+       or      a, b
+       jr      Z, memmove_end
+       ld      e, 4(ix)
+       ld      d, 5(ix)
+       ld      l, 6(ix)
+       ld      h, 7(ix)
+       ld      a, l
+       sbc     hl, de  ; or above cleared carry.
+       ld      l, a
+       ld      h, 7(ix)
+       jr      NC, memmove_up
+memmove_down:
+       add     hl, bc
+       dec     hl
+       ld      a, e
+       add     a, c
+       ld      e, a
+       ld      a, d
+       adc     a, b
+       ld      d, a
+       dec     de
+       lddr
+       jr      memmove_end
+memmove_up:
+       ldir
+memmove_end:
+       ld      l, 4(ix)
+       ld      h, 5(ix)
+       pop     ix
+       ret
+