home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / talinasm.lha / str_subi.asm < prev    next >
Encoding:
Assembly Source File  |  1991-05-19  |  1.2 KB  |  60 lines

  1.  
  2. ;---------------------------------------------
  3. ;    str_subi(str1,str2) - case insensitive substring finder
  4.         xdef    _str_subi
  5.  
  6. _str_subi
  7.         movem.l    d2/d4/d5/a2/a3,-(sp)
  8.  
  9.         move.l    24(sp),a2        ; str1 currently at 24(sp) [20 + 4]
  10.         move.l    a2,a0
  11.         moveq    #-1,d4            ; d4 has str_len of str1
  12. 5$        addq.l    #1,d4
  13.         tst.b    (a0)+
  14.         bne.s    5$
  15.  
  16.         move.l    28(sp),a3        ; str2 currently at 28(sp) [20 + 8]
  17.         move.l    a3,a0
  18.         moveq    #-1,d5
  19. 6$        addq.l    #1,d5            ; d5 has str_len of str2
  20.         tst.b    (a0)+
  21.         bne.s    6$
  22.  
  23. 2$        cmp.l    d5,d4            ; is str2 longer than whats left of str1?
  24.         blt.s    1$                ; yes, exit loop
  25.  
  26.         subq.l    #1,d4            ; reduce str1 length
  27.  
  28.         move.l    a2,a0            ; do a str_ncmp
  29.         addq.w    #1,a2            ; increment address
  30.         move.l    a3,a1
  31.         move.l    d5,d2
  32.         bra.s    11$
  33.  
  34. 10$        move.b    (a0)+,d1        ; are current bytes different?
  35.         cmp.b    #'a',d1
  36.         blt.s    20$
  37.         sub.b    #'a'-'A',d1
  38. 20$        move.b    (a1)+,d0
  39.         cmp.b    #'a',d0
  40.         blt.s    21$
  41.         sub.b    #'a'-'A',d0
  42. 21$        sub.b    d1,d0
  43.         bne.s    2$                ; yes, so failed on this check
  44.  
  45. 11$
  46.     ifnd    BIGSTRING
  47.         dbra    d2,10$            ; continue loop
  48.     else
  49.         subq.w    #1,d2
  50.         bpl.s    10$
  51.     endc
  52.  
  53.         move.l    a2,d0            ; found a match, so save as return value
  54.         subq.l    #1,d0            ; but we did increment it
  55.         bra.s    4$
  56.  
  57. 1$        moveq    #0,d0
  58. 4$        movem.l (sp)+,d2/d4/d5/a2/a3
  59.         rts
  60.