Write a procedure called Str_nextWord that scans a string for the first occurrence of a certain delimiter character and replaces the delimiter with a null byte. There are two input parameters: a pointer to the string and the delimiter character. After the call, if the delimiter was found, the Zero flag is set and EAX contains the offset of the next character beyond the delimiter. Otherwise, the Zero flag is clear and EAX is undefined. The following example code passes the address of target and a comma as the delimiter:

Respuesta :

Answer:

Str_nextword PROC, pString:PTR BYTE, ; pointer to string delimiter:BYTE ; delimiter to find push esi mov al,delimiter mov esi,pString cld ; clear Direction flag (forward) L1: lodsb ; AL = [esi], inc(esi) cmp al,0 ; end of string? je L3 ; yes: exit with ZF = 0 cmp al,delimiter ; delimiter found? jne L1 ; no: repeat loop L2: mov BYTE PTR [esi-1],0 ; yes: insert null byte mov eax,esi ; point EAX to next character jmp Exit_proc ; exit with ZF = 1 L3: or al,1 ; clear Zero flag Exit_proc: pop esi ret Str_nextword ENDP

Explanation:

push esimov al,delimitermov esi,pStringcld ; clear Direction flag (forward)L1: lodsb ; AL = [esi], inc(esi)cmp al,0 ; end of string?je L3 ; yes: exit with ZF = 0cmp al,delimiter ; delimiter found?jne L1 ; no: repeat loopL2: mov BYTE PTR [esi-1],0 ; yes: insert null bytemov eax,esi ; point EAX to next characterjmp Exit_proc ; exit with ZF = 1L3: or al,1 ; clear Zero flagExit_proc:pop esiretStr_nextword ENDPStr_nextword ENDP