.title inchr Find Index of Character in a String .ident /000005/ ; ;+ ; ; Index Find the index of a character in a string ; ; Usage ; ; char * ; inchr(stng, chr) ; char *stng; /* String to search in */ ; char chr; /* Byte to search for */ ; ; Description ; ; If chr is in stng, return its index, i.e. the offset in bytes from ; the beginning of the string - inchr("abc",'b') == 1. If chr is not ; in stng, return -1. ; ; See also strchr(). ; ; Bugs ; ;- ; ; Edit history ; 000001 21-Oct-81 MM Initial edit ; 000002 24-Jun-82 MM Just redefine the global ; 000003 06-Jul-82 MM Too good to be true ; 000004 14-Jul-82 JSL Revived from the dead - index() returns an index, ; strchr() a pointer ; 000005 20-Jul-82 JSL Name changed for Unix compatibility ; .psect c$code inchr:: ;05 mov r2,-(sp) ; Get a register ;04+ mov <2+2>(sp),r1 ; Pick up 'stng' mov <2+4>(sp),r2 ; And 'chr' mov r1,r0 ; Save a copy of 'stng' 10$: cmpb (r1),r2 ; Are they the same? beq 20$ ; Yes, exit tstb (r1)+ ; At string end? bne 10$ ; Br if not. mov #-1,r0 ; Yes, return -1 br 30$ 20$: sub r1,r0 ; Negated offset neg r0 ; Now it's right 30$: mov (sp)+,r2 ; Restore register return ;04- .end