home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / TASMEXMP.ZIP / FINDCHAR.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  1.0 KB  |  29 lines

  1. ; Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. ; FINDCHAR.ASM  - Searching for the last character of a null terminated string
  4.  
  5. ; From the Turbo Assembler Users Guide
  6.  
  7.         .MODEL  small
  8.         .CODE
  9.         PUBLIC _FindLastChar
  10. _FindLastChar   PROC
  11.         ARG     StringToScan:WORD
  12.         push    bp
  13.         mov     bp,sp
  14.         cld             ;we need string instructions to count up
  15.         mov     ax,ds
  16.         mov     es,ax   ;set ES to point to the near data segment
  17.         mov     di, [StringToScan]   ;point ES:DI to start of 
  18.                                      ;passed string
  19.         mov     al,0    ;search for the null that ends the string
  20.         mov     cx,0ffffh  ;search up to 64K-1 bytes
  21.         repnz   scasb      ;look for the null
  22.         dec     di         ;point back to the null
  23.         dec     di         ;point back to the last character
  24.         mov     ax,di      ;return the near pointer in AX
  25.         pop     bp
  26.         ret
  27. _FindLastChar   ENDP
  28.         END
  29.