home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm_kit / ssearch.asm < prev    next >
Assembly Source File  |  1985-06-21  |  2KB  |  58 lines

  1. ;ROUTINE TO SEARCH FOR ONE STRING WITHIN ANOTHER            00000100
  2. ;                                    00000200
  3. strsearch     proc    far                        00000300
  4. ;                                    00000400
  5.           push    si      ;SAVE    REGISTERS            00000500
  6.           push    di                        00000600
  7.           push    cx                        00000700
  8. ;                                    00000800
  9. ;GET LENGTH OF DESTINATION AND POINT TO    FIRST BYTE            00000900
  10. ;                                    00001000
  11.           mov    si,dx      ;USE SOURCE INDEX            00001100
  12.           lodsw          ;GET THE LENGTH OF DESTINATION    00001200
  13.           mov    cx,ax      ;USE THE LENGTH AS COUNT        00001300
  14.           mov    dx,si      ;TEXT    BEGINS HERE            00001400
  15. ;                                    00001500
  16. strsearch1:                                00001600
  17. ;                                    00001700
  18. ;POINT INDICES TO BEGINNING OF SOURCE AND DESTINATION            00001800
  19.           mov    si,bx      ;LOAD    SOURCE INDEX            00001900
  20.           mov    di,dx      ;LOAD    DESTINATION INDEX        00002000
  21. ;                                    00002100
  22. ;SCAN FOR MATCH                                00002200
  23.           mov    al,[si+2] ;GET THE FIRST CHARACTER        00002300
  24.           cld          ;FORWARD DIRECTION            00002400
  25.           repnz    scasb      ;SCAN    FOR MATCH            00002500
  26.           jcxz    strsearch2   ;QUIT IF FOUND NO MATCH        00002600
  27. ;                                    00002700
  28. ;HAVE A    MATCH OF FIRST CHARACTERS- NOW CHECK ENTIRE STRING        00002800
  29.           mov    dx,di      ;SAVE    CURRENT    DEST. LOCATION        00002900
  30.           dec    di      ;BEGINNING OF    WORD            00003000
  31.           lodsw          ;GET LENGTH OF SOURCE            00003100
  32.           xchg    cx,ax      ;USE SOURCE COUNT AND    SAVE DEST. COUNT00003200
  33.           repz    cmpsb      ;COMPARE THE TWO STRINGS        00003300
  34.           jcxz    strsearch3   ;IT'S A MATCH IF NO MORE SOURCE    00003400
  35. ;                                    00003500
  36. ;CONTINUE THE SCAN                            00003600
  37.           xchg    cx,ax      ;USE DEST. COUNT            00003700
  38.           jmp    strsearch1    ;BACK FOR    MORE SCANNING OF DEST.    00003800
  39. ;                                    00003900
  40. ;NO MATCH IS POSSIBLE                            00004000
  41. strsearch2:                                00004100
  42.           mov    al,0h      ;UNSUCCESSFUL    OUTCOME            00004200
  43.           jmp    strsearchexit                    00004300
  44. ;                                    00004400
  45. ;FOUND A MATCH                                00004500
  46. strsearch3:                                00004600
  47.           dec    dx      ;POINT TO BEGINNING OF MATCH        00004700
  48.           mov    al,0ffh      ;SUCCESSFUL MATCH            00004800
  49.           jmp    strsearchexit                    00004900
  50. ;                                    00005000
  51. strsearchexit:                                00005100
  52.           pop    cx      ;RESTORE REGISTERS            00005200
  53.           pop    di                        00005300
  54.           pop    si                        00005400
  55.           ret                            00005500
  56. ;                                    00005600
  57. strsearch     endp                            00005700
  58.