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

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