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

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