Added timing and asm implementations of strcpy, strcmp, memcpy.
[fw/sdcc] / device / lib / z80 / asm_strings.s
index da0aa8c5cb2db979ba55acdddc8adca6b2891683..fd26392779e4e1a27223e3369045ad800346a6fb 100644 (file)
@@ -14,7 +14,7 @@ _strcpy::
        ld      e,8(ix)
        ld      d,9(ix)
 
-       push    de
+       push    hl
 1$:    
        ld      a,(de)
        ld      (hl),a
@@ -28,4 +28,75 @@ _strcpy::
        pop     de
        ret
 
+; void *memcpy(void *dest, const void *source, int count)
+_memcpy::
+       push    de
+       push    bc
+       push    ix
+       ld      ix,#0
+       add     ix,sp
+       ld      l,8(ix)
+       ld      h,9(ix)
+       ld      e,10(ix)
+       ld      d,11(ix)
+       ld      c,12(ix)
+       ld      b,13(ix)
+
+       inc     b
+       inc     c
+       push    hl
+
+       jr      2$
+1$:
+       ld      a,(de)
+       ld      (hl),a
+       inc     de
+       inc     hl
+2$:
+       dec     c
+       jr      nz,1$
+       dec     b
+       jr      nz,1$   
+
+       pop     hl
+       pop     ix
+       pop     bc
+       pop     de
+       ret
+
+; int strcmp(const char *s1, const char *s2) 
+_strcmp::
+       push    de
+       push    ix
+       ld      ix,#0
+       add     ix,sp
+       ld      e,6(ix)
+       ld      d,7(ix)
+       ld      l,8(ix)
+       ld      h,9(ix)
+
+       jr      1$
+2$:    
+       ld      a,(de)
+       sub     (hl)
+       jr      nz,4$
+       ;; A == 0
+       cp      (hl)
+       jr      z,3$
+1$:    
+       inc     de
+       inc     hl
+       jr      2$
+
+3$:
+       ld      hl,#0
+       jr      5$
+4$:
+       ld      hl,#1
+       jr      nc,5$
+       ld      hl,#-1
+5$:
+       pop     ix
+       pop     de
+       ret
        
\ No newline at end of file