home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 9.ddi / CHAPXMPL.ZIP / SUB1.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-02-13  |  1.6 KB  |  51 lines

  1. ; Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. ; SUB1.ASM
  4.  
  5. ; This is part of the example of linking multiple assembly code modules.
  6. ; This modules provides the ConcatenateStrings function to be called
  7. ; by MAIN.ASM
  8.  
  9.      DOSSEG
  10.      .MODEL    SMALL
  11.      .DATA
  12.      GLOBAL    FinalString:BYTE
  13.      .CODE
  14. ;
  15. ; Subroutine copies first one string, and then another
  16. ; to FinalString.
  17. ;
  18. ; Input:
  19. ;    DS:AX = pointer to first string to copy
  20. ;    DS:BX = pointer to second string to copy
  21. ;
  22. ; Output: None
  23. ;
  24. ; Registers destroyed: AL, SI, DI, ES
  25. ;
  26.      PUBLIC    ConcatenateStrings
  27. ConcatenateStrings  PROC
  28.      cld                         ;strings count up
  29.      mov  di,SEG FinalString
  30.      mov  es,di
  31.      mov  di,OFFSET FinalString
  32.                                  ;ES:DI points to the destination
  33.      mov  si,ax                  ;first string to copy
  34. String1Loop:
  35.      lodsb                       ;get string 1 character
  36.      and  al,al                  ;is it 0?
  37.      jz   DoString2              ;yes, done with string 1
  38.      stosb                       ;save string 1 character
  39.      jmp  String1Loop
  40. DoString2:
  41.      mov  si,bx                  ;second string to copy
  42. String2Loop:
  43.      lodsb                       ;get string 2 character
  44.      stosb                       ;save string 2 character
  45.                                  ; (including 0 when we find it)
  46.      and  al,al                  ;is it 0?
  47.      jnz  String2Loop            ;no, do next character
  48.      ret                         ;done
  49. ConcatenateStrings   ENDP
  50.      END
  51.