home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRREV.ASM < prev    next >
Assembly Source File  |  1990-08-10  |  959b  |  66 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ;
  5. ; strrev- reverses the characters in a string.
  6. ;
  7. ; inputs:
  8. ;
  9. ;    ES:DI- Points at the string to reverse.
  10. ;
  11. ;
  12. ; Created by Mike Blaszczak (.B ekiM)  8/8/90
  13. ; Some minor tweaking by R. Hyde 8/9/90
  14. ;
  15. ;
  16.         public    sl_strrev
  17. ;
  18. ;
  19. sl_strrev    proc    far
  20.         push    ds
  21.         push    si
  22.         push    di
  23.         push    ax
  24.         push    cx
  25.         pushf
  26.         cld
  27. ;
  28. ; Init ptr to the start of the string
  29. ;
  30.         mov    si, es
  31.         mov    ds, si
  32.         mov    si, di
  33. ;
  34. ; Compute the length of the string:
  35. ;
  36.         mov    cx, 0ffffh
  37.         mov    al, 0
  38.     repne    scasb
  39.         neg    cx
  40.         dec    cx
  41.         dec    cx
  42.         shr    cx, 1        ;Only have to do half the bytes.
  43.         jcxz    StrRvsd
  44.         dec    di             ;Point at zero byte.
  45. ;
  46. ; Okay, swap the bytes in the string.
  47. ;
  48. SwapBytes:    dec    di
  49.         lodsb
  50.         xchg    al, [di]    ;Note: es=ds.
  51.         mov    -1[si], al
  52.         loop    SwapBytes
  53. ;
  54. StrRvsd:        popf
  55.         pop    cx
  56.         pop    ax
  57.         pop    di
  58.         pop    si
  59.         pop    ds
  60.         ret
  61. sl_strrev    endp
  62. ;
  63. ;
  64. stdlib        ends
  65.         end
  66.