Annotation of coherent/b/lib/libc/string/i8086/strstr.m, revision 1.1.1.1

1.1       root        1: //////////
                      2: / i8086 C string library.
                      3: / strstr()
                      4: / ANSI 4.11.5.7.
                      5: //////////
                      6: 
                      7: //////////
                      8: / char *
                      9: / strstr(s1, s2)
                     10: / char *s1, *s2;
                     11: /
                     12: / Return the first occurance in s1 of s2.
                     13: / If s2 is empty, return s1.
                     14: //////////
                     15: 
                     16: #include <larges.h>
                     17: 
                     18: s1     =       LEFTARG
                     19: s2     =       s1+DPL
                     20: 
                     21:        Enter(strstr_)
                     22:        Lds     bx, s1(bp)      / s1 address to DS:BX
                     23:        Les     di, s2(bp)      / s2 address to ES:DI
                     24:        mov     dx, di          / Save s2 start in DX
                     25:        mov     cx, $-1         / Max count to CX
                     26:        sub     ax, ax
                     27:        cld
                     28:        repne
                     29:        scasb                   / Scan to NUL
                     30:        dec     di              / Back up to match
                     31:        mov     ax, di
                     32:        sub     ax, dx          / &NUL - &start = length of s2 to AX
                     33:        je      3f              / s2 is empty, just return s1
                     34: 
                     35: 1:     mov     cx, ax          / Count to CX
                     36:        mov     di, dx          / s2 address to ES:DI
                     37:        mov     si, bx          / Current location within s1 to DS:SI
                     38:        repe
                     39:        cmpsb                   / Compare entire s2 to current s1
                     40:        je      3f              / Success, return current location
                     41:        inc     bx              / Mismatched, try next s1 location
                     42:        cmpb    -1(si), $0      / Check if end of s1 reached
                     43:        jne     1b              / No, keep trying
                     44: 
                     45: 2:     sub     ax, ax          / Failure, return NULL
                     46: #ifdef LARGEDATA
                     47:        mov     dx, ax
                     48: #endif
                     49:        jmp     4f
                     50: 
                     51: 3:     mov     ax, bx          / Success, return pointer on s1
                     52: #ifdef LARGEDATA
                     53:        mov     dx, ds
                     54: #endif
                     55: 
                     56: 4:     Leave

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.