When I programmed in PL/M-86 during the eighties to mid-nineties there were some built-in functions that I liked a lot, especially for text searches.
int findb (void *,char,int);
int findrb (void *,char,int);
int skipb (void *,char,int);
int skiprb (void *,char,int);
int cmpb (void *,void *,int);
int cmprb (void *,void *,int);
findb/findrb scanned a buffer (void *) of x (int) length for the first/last match for a byte (char). Upon completion the returned value would contain the index of the first/last match. If there was no match 0xffff would be returned.
skipb/skiprb scanned a buffer (void *) of x (int) length for the first/last non-match for a byte (char). Upon completion the returned value would contain would be the index of the first/last non-match. If there was no non-match 0xffff would be returned.
cmpb/cmprb compares two buffers of x (int) length byte by byte and reports the position of the first non-match. If the buffers were equal 0xffff would be returned.
I've included the OpenWatcom inline assembly definitions for the 32-bit x86:
#pragma aux cmpb = \
"all_same_0:"\
" mov edx,ecx"\
" jecxz all_same_1"\
" repe cmpsb"\
" je short all_same_0"\
" sub edx,ecx"\
"all_same_1:"\
"dec edx"\
parm [esi][edi][ecx] modify exact [ecx edx esi edi] value [edx];
#pragma aux cmprb = \
"jecxz all_same"\
" lea esi,[esi+ecx-1]"\
" lea edi,[edi+ecx-1]"\
" std"\
" repe cmpsb"\
" cld"\
" jne short not_same"\
"all_same:"\
"dec ecx"\
"not_same:"\
parm [esi][edi][ecx] modify exact [ecx esi edi] value [ecx];
#pragma aux findb = \
"not_found_0:"\
"mov edx,ecx"\
"jecxz not_found_1"\
" repne scasb"\
" jne short not_found_0"\
" sub edx,ecx"\
"not_found_1:"\
"dec edx"\
parm [edi][al][ecx] modify exact [ecx edx edi] value [edx];
#pragma aux skipb = \
"all_same_0:"\
"mov edx,ecx"\
"jecxz all_same_1"\
" repe scasb"\
" je short all_same_0"\
" sub edx,ecx"\
"all_same_1:"\
"dec edx"\
parm [edi][al][ecx] modify exact [ecx edx edi] value [edx];
#pragma aux findrb = \
"jecxz not_found"\
" lea edi,[edi+ecx-1]"\
" std"\
" repne scasb"\
" cld"\
" je short found"\
"not_found:"\
"dec ecx"\
"found:"\
parm [edi][al][ecx] modify exact [ecx edi] value [ecx];
#pragma aux skiprb = \
"jecxz not_found"\
" lea edi,[edi+ecx-1]"\
" std"\
" repe scasb"\
" cld"\
" je short found"\
"not_found:"\
"dec ecx"\
"found:"\
parm [edi][al][ecx] modify exact [ecx edi] value [ecx];