home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / SCAN15.ASM < prev    next >
Assembly Source File  |  1994-10-31  |  2KB  |  75 lines

  1.     page    66,132
  2. ;******************************** SCAN15.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    strlen3:far
  14. comment 
  15. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SEARCH  )
  16. LAST_CHAR - find the last byte in a string matching register AL
  17. ;
  18. ; inputs:    DS:[BX] pointing to the first character of the string
  19. ;            AL = byte to find
  20. ;            
  21. ; output:    if CF = 1, no match
  22. ;            if CF = 0, AX = offset from DS:[BX] of the last matching byte
  23. ;* * * * * * * * * * * * * *
  24. 
  25.     PUBLIC    LAST_CHAR
  26. LAST_CHAR    PROC    FAR
  27.     push    cx
  28.     CALL    strlen3
  29.     call    last_charc
  30.     pop     cx
  31.     retf
  32. LAST_CHAR ENDP
  33. comment 
  34. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SEARCH  )
  35. LAST_CHARC - find the last byte in n bytes matching AL
  36. ;
  37. ; inputs:    DS:[BX] pointing to the first character of the string
  38. ;            AL = byte to find
  39. ;            CX = number of bytes to search
  40. ;            
  41. ; output:    if CF = 1, no match
  42. ;            if CF = 0, AX = offset from DS:[BX] of the last matching byte
  43. ;* * * * * * * * * * * * * *
  44. 
  45.     PUBLIC    LAST_CHARC
  46. LAST_CHARC    PROC    FAR
  47.     APUSH   DI,ES
  48.     STD
  49.     PUSH    DS
  50.     POP     ES
  51.     MOV     DI,BX
  52.     ADD     DI,CX            ;find string end
  53.     DEC     DI                ;  and use as search start
  54.     PUSH    CX
  55.     REPNZ   SCASB            ;scan from end of string for char.
  56.     POP     CX
  57.     JNZ     STRN_NO            ;jmp if char not found
  58.     
  59.     MOV     AX,DI            ;compute
  60.     INC     AX                ;  lenght of search
  61.     SUB     AX,BX            ;     match point -> AX
  62.     
  63.     CLC
  64.     JMP     STRN_EXIT
  65. STRN_NO:    
  66.     STC
  67. STRN_EXIT:    
  68.     APOP    ES,DI
  69.     cld
  70.     RETF
  71. LAST_CHARC    ENDP
  72.  
  73. LIBSEG    ENDS
  74.     end
  75.