>>16 ; in: ; esi = source ; edi = delim ; edx = source length ; ecx = delim length ; out: ; eax = ptr to splits, {ptr,len}, null-terminated, 0 on err ; all registers change, except esp and ebx explode: mov ebp, esp jmp begin_loop exploop: push esi push ecx push edi repnz cmpsb pop edi pop ecx jz match pop esi inc esi dec edx jmp loop_cmp match: pop eax sub eax, [esp] push eax sub edx, ecx begin_loop: push esi loop_cmp: cmp ecx, edx jbe exploop expdone: push edx push 0 sub ebp, esp push ebp shr ebp, 2 call malloc test eax, eax pop ecx jz malerr mov ecx, ebp ; not needed if malloc does not modify arg retloop: pop [eax+ecx*4-4] loop retloop malerr: ret
One pass through p, and one "reallocation" (try doing that in C!)