home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH15 / CONCAT.ASM next >
Encoding:
Assembly Source File  |  1996-02-25  |  1.5 KB  |  62 lines

  1. ; Concat-        Copies the string pointed at by SI to the string 
  2. ;             rointed at by DI and then concatenates the string;
  3. ;            pointed at by BX to the destination string.
  4. ;
  5. ; On entry-
  6. ;
  7. ; DS:SI-        Points at the first source string
  8. ; DS:BX-        Points at the second source string
  9. ; ES:DI-        Points at the destination string.
  10. ;
  11. ; Error condition-
  12. ;
  13. ; The sum of the lengths of the two strings is greater than 255.
  14. ; In this event, the second string will be truncated so that the
  15. ; entire string is less than 256 characters in length.
  16.  
  17. CONCAT        proc    near
  18.         push    si
  19.         push    di
  20.         push    cx
  21.         push    ax
  22.         pushf
  23.  
  24. ; Copy the first string to the destination string:
  25.  
  26.         mov    al, [si]
  27.         mov    cl, al
  28.         mov    ch, 0
  29.         mov    ah, ch
  30.         add    al, [bx]    ;Compute the sum of the stringâ•’s
  31.         adc    ah, 0        ; lengths.
  32.         cmp    ax, 256
  33.         jb    SetNewLength
  34.         mov    ah, [si]    ;Save original string length.
  35.         mov    al, 255        ;Fix string length at 255.
  36. SetNewLength:    mov    es:[di], al    ;Save new string length.
  37.         inc    di        ;Skip over length bytes.
  38.         inc    si
  39.     rep    movsb            ;Copy source1 to dest string.
  40.  
  41. ; If the sum of the two strings is too long, the second string
  42. ; must be truncated.
  43.  
  44.         mov    cl, [bx]    ;Get length of second string.
  45.         cmp    ax, 256
  46.         jb    LengthsAreOK
  47.         mov    cl, ah        ;Compute truncated length.
  48.         neg    cl        ;CL := 256-Length(Str1).
  49.  
  50. LengthsAreOK:    lea    si, 1[bx]    ;Point at second string and
  51. ;                    ; skip the string length.
  52.         cld
  53.         rep    movsb        ;Perform the concatenation.
  54.  
  55.         popf
  56.         pop    ax
  57.         pop    cx
  58.         pop    di
  59.         pop    si
  60.         ret
  61. CONCAT        endp
  62.