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

  1. ;
  2. ; *** Listing 11-4 ***
  3. ;
  4. ; Converts all characters in a string to uppercase,
  5. ; using a loop containing non-string instructions
  6. ; and using only one pointer.
  7. ;
  8.     jmp    Skip
  9. ;
  10. SourceString    label    word
  11.     db    'This space intentionally left not blank',0
  12. ;
  13. ; Converts a string to uppercase.
  14. ;
  15. ; Input:
  16. ;    DS:SI = start of string
  17. ;
  18. ; Output:
  19. ;    none
  20. ;
  21. ; Registers altered: AL, BX, SI
  22. ;
  23. ; Note: Does not handle strings that are longer than 64K
  24. ;    bytes or cross segment boundaries.
  25. ;
  26. StringToUpper:
  27.     mov    bl,'a'    ;set up for fast register-register
  28.     mov    bh,'z'    ; comparisons
  29. StringToUpperLoop:
  30.     mov    al,[si]    ;get the next character
  31.     cmp    al,bl    ;below 'a'?
  32.     jb    IsUpper    ;yes, not lowercase
  33.     cmp    al,bh    ;above 'z'?
  34.     ja    IsUpper    ;yes, not lowercase
  35.     and    al,not 20h ;is lowercase-make uppercase
  36. IsUpper:
  37.     mov    [si],al    ;put the uppercase character back
  38.     inc    si    ; into the string and point to the
  39.             ; following character
  40.     and    al,al    ;is this the zero that marks the
  41.             ; end of the string?
  42.     jnz    StringToUpperLoop ;no, do the next character
  43.     ret
  44. ;
  45. Skip:
  46.     call    ZTimerOn
  47.     mov    si,offset SourceString    ;point to the string
  48.                     ; to convert
  49.     call    StringToUpper        ;convert it to
  50.                     ; uppercase
  51.     call    ZTimerOff
  52.