home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRCAT2.ASM < prev    next >
Assembly Source File  |  1990-07-14  |  2KB  |  121 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4.         extrn    sl_malloc:far
  5. ;
  6. ; strcat2-Computes the lengths of two strings pointed at by es:di and dx:si
  7. ;      then allocates storage for a string long enough to hold the con-
  8. ;      catentation of these two strings.  Finally, it concatenates the
  9. ;      two strings storing the resulting string into the new buffer.
  10. ;      Returns ED:SI pointing at the new string.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    ES:DI- Points at the first string.
  15. ;
  16. ;    DX:SI- Points at the string to append.
  17. ;
  18. ;
  19. ; outputs:
  20. ;
  21. ;    ES:DI- Points at new string containing the concatenation of the
  22. ;           two strings.
  23. ;
  24. ;    carry=0 if no error.
  25. ;    carry=1 if strcat2 could not allocate enough memory to hold
  26. ;        the resulting string.
  27. ;
  28.         public    sl_strcat2
  29. ;
  30. scptr1        dd    ?
  31. strlen1        dw    ?
  32. scptr2        dd    ?
  33. strlen2        dw    ?
  34. ;
  35. sl_strcat2    proc    far
  36.         push    ds
  37.         push    si
  38.         push    cx
  39.         push    ax
  40.         pushf
  41.         cld
  42. ;
  43. ; Save pointers to the strings
  44. ;
  45.         mov    word ptr cs:scptr1, di
  46.         mov    word ptr cs:scptr1+2, es
  47.         mov    word ptr cs:scptr2, si
  48.         mov    word ptr cs:scptr2+2, dx
  49. ;
  50. ; Compute the length of the second string.
  51. ;
  52.         mov    al, 0
  53.         les    di, cs:scptr2
  54.         mov    cx, 0ffffh
  55.     repne    scasb
  56.         neg    cx
  57.         dec    cx
  58.         mov    cs:StrLen2, cx
  59. ;
  60. ; Find the end of the first string:
  61. ;
  62.         les    di, cs:scptr1
  63.         mov    cx, 0ffffh
  64.     repne    scasb
  65.         neg    cx
  66.         dec    cx
  67.         dec    cx
  68.         mov    cs:StrLen1, cx
  69. ;
  70. ; Malloc the appropriate storage:
  71. ;
  72.         add    cx, cs:StrLen2
  73.         call    sl_malloc
  74.         jc    BadStrCat2
  75. ;
  76. ; Save ptr to dest
  77. ;
  78.         push    es
  79.         push    di        
  80. ;
  81. ; Copy the strings:
  82. ;
  83.         lds    si, cs:scptr1
  84.         mov    cx, cs:strlen1
  85.         shr    cx, 1
  86.         jnc    cs1
  87.         lodsb
  88.         stosb
  89. cs1:    rep    movsw
  90.         lds    si, cs:scptr2
  91.         mov    cx, cs:strlen2
  92.         shr    cx, 1
  93.         jnc    cs2
  94.         lodsb
  95.         stosb
  96. cs2:    rep    movsw
  97. ;
  98.         pop    di
  99.         pop    es
  100.         popf
  101.         pop    ax
  102.         pop    cx
  103.         pop    si
  104.         pop    ds
  105.         clc
  106.         ret
  107. ;
  108. BadStrCat2:    les    di, cs:scptr1
  109.         popf
  110.         pop    ax
  111.         pop    cx
  112.         pop    si
  113.         pop    ds
  114.         stc
  115.         ret
  116. sl_strcat2    endp
  117. ;
  118. ;
  119. stdlib        ends
  120.         end
  121.