home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST13-13.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  82 lines

  1. ;
  2. ; *** Listing 13-13 ***
  3. ;
  4. ; Copies a zero-terminated string to another string,
  5. ; optionally converting characters to uppercase. The
  6. ; decision as to whether to convert to uppercase is made
  7. ; once for each character.
  8. ;
  9.     jmp    Skip
  10. ;
  11. SourceString    label    byte
  12.     db    'This is a sample string, consisting of '
  13.     db    'both uppercase and lowercase characters.'
  14.     db    0
  15. DestinationString    label    byte
  16.     db    100 dup (?)
  17. ;
  18. ; Copies a zero-terminated string to another string,
  19. ; optionally converting characters to uppercase.
  20. ;
  21. ; Input:
  22. ;    DL = 1 if conversion to uppercase during copying is
  23. ;        desired, 0 otherwise
  24. ;    DS:SI = source string
  25. ;    ES:DI = destination string
  26. ;
  27. ; Output: none
  28. ;
  29. ; Registers altered: AL, SI, DI
  30. ;
  31. ; Direction flag cleared
  32. ;
  33. ; Note: Does not handle strings that are longer than 64K
  34. ;    bytes or cross segment boundaries.
  35. ;
  36. CopyAndConvert:
  37.     cld
  38. CopyAndConvertLoop:
  39.     lodsb                ;get the next byte
  40.                     ; to check
  41.     and    dl,dl            ;conversion to
  42.                     ; uppercase desired?
  43.     jz    CopyAndConvertUC    ;no
  44.     cmp    al,'a'            ;less than 'a'?
  45.     jb    CopyAndConvertUC    ;yes, not lowercase
  46.     cmp    al,'z'            ;greater than 'z'?
  47.     ja    CopyAndConvertUC    ;yes, not lowercase
  48.     and    al,not 20h        ;make it uppercase
  49. CopyAndConvertUC:
  50.     stosb                ;put the byte in the
  51.                     ; destination string
  52.     and    al,al            ;was that the
  53.                     ; terminating zero?
  54.     jnz    CopyAndConvertLoop    ;no, do next byte
  55.     ret
  56. ;
  57. Skip:
  58.     call    ZTimerOn
  59. ;
  60. ; First, copy without converting to uppercase.
  61. ;
  62.     mov    di,seg DestinationString
  63.     mov    es,di
  64.     mov    di,offset DestinationString
  65.             ;ES:DI points to the destination
  66.     mov    si,offset SourceString
  67.             ;DS:SI points to the source
  68.     sub    dl,dl    ;don't convert to uppercase
  69.     call    CopyAndConvert    ;copy without converting
  70.                 ; to uppercase
  71. ;
  72. ; Now copy and convert to uppercase.
  73. ;
  74.     mov    di,offset DestinationString
  75.             ;ES:DI points to the destination
  76.     mov    si,offset SourceString
  77.             ;DS:SI points to the source
  78.     mov    dl,1    ;convert to uppercase this time
  79.     call    CopyAndConvert    ;copy and convert to
  80.                 ; uppercase
  81.     call    ZTimerOff
  82.