home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / STRCAT.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.8 KB  |  98 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strcat.c
  3.  *
  4.  * function(s)
  5.  *        strcat - appends one string to another
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma  inline
  19. #include <asmrules.h>
  20. #include <string.h>
  21.  
  22. /*---------------------------------------------------------------------*
  23.  
  24. Name            strcat - appends one string to another
  25.  
  26. Usage           char *strcat(char *destin, const char *source);
  27.  
  28. Prototype in    string.h
  29.  
  30. Description     strcat appends a copy of source to the end of destin. The
  31.                 length of the resulting string is strlen(destin) +
  32.                 strlen(source).
  33.  
  34. Return value    returns a pointer dest
  35.  
  36. *---------------------------------------------------------------------*/
  37. #undef strcat                   /* not an intrinsic */
  38. char *_CType strcat(register char *dest, const char *src)
  39. {
  40.         SaveSI
  41.         SaveDI
  42.  
  43. asm    cld
  44. #if  defined(__LARGE__) || defined(__COMPACT__)
  45. asm    push    ds
  46. #endif
  47. #if LDATA
  48. asm    les    di, dest    /* es:di = dest */
  49. #else
  50. asm    mov    di, dest    /* es:di = dest */
  51. asm    push    ds
  52. asm    pop    es
  53. #endif
  54. asm    mov    dx, di        /* save dest offset in dx */
  55. asm    xor    al, al
  56. asm    mov    cx, -1        /* find end of dest */
  57. asm    repne  scasb
  58. #if LDATA
  59. asm    push    es
  60. #endif
  61. asm    lea    si,[di-1]    /* es:si points to terminating null in dest */
  62. asm    LES_    di, src
  63. asm    mov    cx,-1        /* figure out strlen(src) */
  64. asm    repne  scasb
  65. asm    not    cx        /* CX = strlen(src) + 1 */
  66. asm    sub    di,cx        /* point es:di back to start of src */
  67. #if LDATA
  68. asm    push    es
  69. asm    pop    ds        /* set DS: to seg of src */
  70. asm    pop    es        /* restore ES: as seg of dest */
  71. #endif
  72. asm    xchg    si, di        /* DS:SI = src, ES:DI = dest+strlen(dest) */
  73. asm    test    si,1        /* odd src? */
  74. asm    jz    move_rest
  75. asm    movsb            /* move a byte to make src even */
  76. asm    dec    cx
  77. move_rest:
  78. asm    shr    cx, 1
  79. asm    rep  movsw
  80. asm    jnc    move_last
  81. asm    movsb
  82. move_last:
  83. asm     xchg    ax, dx                  /* return addr of string */
  84. #if LDATA
  85. asm    mov    dx, es
  86. #endif
  87. #if  defined(__LARGE__) || defined(__COMPACT__)
  88. asm    pop    ds
  89. #endif
  90.  
  91. #if LDATA
  92.         return( (char *)(MK_LONG) );
  93. #else
  94.         return( (char *)_AX );
  95. #endif
  96. }
  97.  
  98.