Annotation of coherent/b/lib/libc/string/i8086/strrchr.m, revision 1.1

1.1     ! root        1: //////////
        !             2: / i8086 C string library.
        !             3: / strrchr()
        !             4: / ANSI 4.11.5.5.
        !             5: / Previously known as rindex().
        !             6: / Entry point for rindex() retained for backward compatability.
        !             7: //////////
        !             8: 
        !             9: //////////
        !            10: / char *
        !            11: / strrchr(String, Char)
        !            12: / char *String;
        !            13: / int Char;
        !            14: /
        !            15: / Find rightmost occurence of Char in String,
        !            16: / return pointer or NULL.
        !            17: //////////
        !            18: 
        !            19: #include <larges.h>
        !            20: 
        !            21: String =       LEFTARG
        !            22: Char   =       String+DPL
        !            23: 
        !            24:        .globl  strrchr_
        !            25: strrchr_:
        !            26: 
        !            27:        Enter(rindex_)
        !            28:        Lds     si, String(bp)  / String address to DS:SI
        !            29:        movb    ah, Char(bp)    / Char to AH
        !            30:        sub     bx, bx          / Address of last match to BX
        !            31:        cld
        !            32: 
        !            33: 1:     lodsb                   / Fetch String char to AL
        !            34:        cmpb    al, ah          / and compare to Char
        !            35:        jne     2f              / Mismatch
        !            36:        mov     bx, si          / Match, save address
        !            37: 
        !            38: 2:     orb     al, al          / Test for NUL
        !            39:        jne     1b              / Not done
        !            40:        or      bx, bx          / End of string, test if match found
        !            41:        jne     3f              / Match found
        !            42:        mov     ax, bx          / No match, return NULL
        !            43: #if    LARGEDATA
        !            44:        mov     dx, ax
        !            45: #endif
        !            46:        jmp     4f              / Go home
        !            47: 
        !            48: 3:     dec     bx              / Back up to match
        !            49:        mov     ax, bx          / AX = offset
        !            50: #if    LARGEDATA
        !            51:        mov     dx, ds          / DX = segment
        !            52: #endif
        !            53: 
        !            54: 4:     Leave

unix.superglobalmegacorp.com

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