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

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4.         extrn    sl_malloc:far
  5. ;
  6. ; strcat- Computes the lengths of two strings pointed at by es:di and follow-
  7. ;      ing the call.  It then allocates storage for a string long enough 
  8. ;      to hold the concatentation of these two strings.  Finally, it con-
  9. ;      catenates the two strings storing the resulting string into the new
  10. ;      buffer.  Returns ES:DI pointing at the new string.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    ES:DI-    Points at the first string.
  15. ;
  16. ;    Return address 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_strcat2l
  29. ;
  30. scptr1        dd    ?
  31. strlen1        dw    ?
  32. scptr2        equ    2[bp]
  33. rtnadrs        dw    ?
  34. strlen2        dw    ?
  35. ;
  36. sl_strcat2l    proc    far
  37.         push    bp
  38.                 mov    bp, sp
  39.         push    cx
  40.         push    ax
  41.         push    ds
  42.         push    si
  43.         pushf
  44.         cld
  45. ;
  46. ; Save pointers to the strings
  47. ;
  48.         mov    word ptr cs:scptr1, di
  49.         mov    word ptr cs:scptr1+2, es
  50. ;
  51. ; Compute the length of the string following the call.
  52. ;
  53.         mov    al, 0
  54.         les    di, scptr2
  55.         mov    cx, 0ffffh
  56.     repne    scasb
  57.         mov    cs:rtnadrs, di        ;Save return address
  58.         neg    cx
  59.         dec    cx
  60.         mov    cs:StrLen2, cx
  61. ;
  62. ; Find the end of the first string:
  63. ;
  64.         les    di, cs:scptr1
  65.         mov    cx, 0ffffh
  66.     repne    scasb
  67.         neg    cx
  68.         dec    cx
  69.         dec    cx
  70.         mov    cs:StrLen1, cx
  71. ;
  72. ; Malloc the appropriate storage:
  73. ;
  74.         add    cx, cs:StrLen2
  75.         call    sl_malloc
  76.         jc    BadStrCat2
  77. ;
  78. ; Save ptr to dest
  79. ;
  80.         push    es
  81.         push    di        
  82. ;
  83. ; Copy the strings:
  84. ;
  85.         lds    si, cs:scptr1
  86.         mov    cx, cs:strlen1
  87.         shr    cx, 1
  88.         jnc    cs1
  89.         lodsb
  90.         stosb
  91. cs1:    rep    movsw
  92.         lds    si, scptr2
  93.         mov    cx, cs:strlen2
  94.         shr    cx, 1
  95.         jnc    cs2
  96.         lodsb
  97.         stosb
  98. cs2:    rep    movsw
  99. ;
  100.         mov    ax, cs:rtnadrs
  101.         mov    scptr2, ax
  102.         pop    di
  103.         pop    es
  104.         popf
  105.         pop    si
  106.         pop    ds
  107.         pop    ax
  108.         pop    cx
  109.         pop    bp
  110.         clc
  111.         ret
  112. ;
  113. BadStrCat2:    mov    es, word ptr cs:scptr1+2
  114.         mov    si, word ptr cs:scptr1
  115.         mov    ax, cs:rtnadrs
  116.         mov    scptr2, ax
  117.         popf
  118.         pop    di
  119.         pop    ds
  120.         pop    ax
  121.         pop    cx
  122.         pop    bp
  123.         stc
  124.         ret
  125. sl_strcat2l    endp
  126. ;
  127. ;
  128. stdlib        ends
  129.         end
  130.