home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / BLKCPY.S < prev    next >
Encoding:
Text File  |  1987-10-10  |  1.1 KB  |  54 lines

  1. *    char *blkcpy(dest, source, len)
  2. *    register char *dest;
  3. *    register char *source;
  4. *    register int len;
  5. *    /*
  6. *     *    Copies the <source> block to the <dest>.  <len> bytes are
  7. *     *    always copied.  No terminator is added to <dest>.  A pointer
  8. *     *    to <dest> is returned.
  9. *     */
  10. *    {
  11. *        register char *p = dest;
  12. *    
  13. *        if(source < dest) {
  14. *            dest += len;
  15. *            source += len;
  16. *            while(len--)
  17. *                *--dest = *--source;
  18. *        }
  19. *        else {
  20. *            while(len--)
  21. *                *dest++ = *source++;
  22. *        }
  23. *        return(p);
  24. *    }
  25.  
  26. .text
  27. .globl _lblkcpy
  28. _lblkcpy:
  29.     move.l    12(a7),d0    ; number of bytes
  30.     bra    blkcpy0
  31. .globl _blkcpy
  32. _blkcpy:
  33.     move.w    12(a7),d0    ; number of bytes
  34. blkcpy0:
  35.     move.l    4(a7),a1    ; destination
  36.     move.l    8(a7),a0    ; source
  37.     cmp.l    a0,a1        ; check copy direction
  38.     ble    blkcpy4
  39.     add.l    d0,a0        ; move pointers to end
  40.     add.l    d0,a1
  41.     bra    blkcpy2
  42. blkcpy1:
  43.     move.b    -(a0),-(a1)    ; (s < d) copy loop
  44. blkcpy2:
  45.     dbra    d0,blkcpy1
  46.     bra    blkcpy5
  47. blkcpy3:
  48.     move.b    (a0)+,(a1)+    ; (s >= d) copy loop
  49. blkcpy4:
  50.     dbra    d0,blkcpy3
  51. blkcpy5:
  52.     move.l    4(a7),d0    ; return destination pointer
  53.     rts
  54.