;       Static Name Aliases
;
        TITLE   index
;       NAME    index.C

;  int  index(src, obj)
;       char *src;
;       char obj;
;
;  Returns the integer offset of character obj within string src.
;  Returns -1 if obj is not found within src.
;
;  index(src, '\0') is equivalent to strlen(src)
;

        .287
_TEXT   SEGMENT  BYTE PUBLIC 'CODE'
_TEXT   ENDS
_DATA   SEGMENT  WORD PUBLIC 'DATA'
_DATA   ENDS
CONST   SEGMENT  WORD PUBLIC 'CONST'
CONST   ENDS
_BSS    SEGMENT  WORD PUBLIC 'BSS'
_BSS    ENDS
DGROUP  GROUP   CONST,  _BSS,   _DATA
        ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
_TEXT      SEGMENT
        PUBLIC  _index
_index  PROC NEAR
        push    bp
        mov     bp,sp
        push    di
        push    si
        mov     si,[bp+4]       ;s
        mov     di,si
; Line 6
;       s = 4
;       register si = s
;       c = 6

        mov     bl,[bp+6]       ;c
$cmp:
        lodsb
        cmp     al,bl
        je      cleanup
        cmp     al,0
        je      $nofind
        jmp     $cmp
$nofind:
        xor     ax,ax
        jmp     short out
cleanup:
        xchg    ax,si
        sub     ax,di
out:
        dec     ax
        pop     si
        pop     di
        mov     sp,bp
        pop     bp
        ret

_index  ENDP
_TEXT   ENDS
END
