Si repne scasb
trouve l'élément, EDI
des points à l'élément après le premier match. Vous devez le décrémenter pour obtenir le pointeur sur l'élément désiré.
Vous n'avez pas besoin d'effacer le drapeau de direction (cld
). Il est très peu probable que le drapeau de direction soit défini sans aucune implication de votre part. Et si c'est le cas, vous devriez revenir à l'ancien statut.
INCLUDE Irvine32.inc
.DATA
selectedWords BYTE "BICYCLE"
inputLetter BYTE 'Y'
err_msg BYTE "Not found.", 0
.CODE
main PROC
mov ecx, LENGTHOF selectedWords
mov edi, offset selectedWords
mov al, inputLetter ; Load character to find
repne scasb ; Search
jne notfound
dec edi
mov al, [edi]
call WriteChar ; Irvine32: Write a character in AL
exit ; Irvine32: ExitProcess
notfound:
lea edx, err_msg
call WriteString ; Irvine32: Write a null-terminated string pointed to by EDX
exit ; Irvine32: ExitProcess
main ENDP
END main
Si vous n'aimez pas repne scasb
vous pouvez scanner le mot avec une boucle de comparaison « normale »
INCLUDE Irvine32.inc
.DATA
selectedWords BYTE "BICYCLE"
inputLetter BYTE 'Y'
err_msg BYTE "Not found.", 0
.CODE
main PROC
mov edi, offset selectedWords
mov ecx, LENGTHOF selectedWords
mov al, inputLetter
@@:
cmp [edi], al ; Compare memory/immediate value
je found ; JE = jump if equal
inc edi ; Increment pointer
dec ecx ; Decrement counter
jne @B ; Jump back to the last @@, if ECX == 0
jmp notfound
found:
mov al, [edi]
call WriteChar ; Irvine32: Write a character in AL
exit ; Irvine32: ExitProcess
notfound:
lea edx, err_msg
call WriteString ; Irvine32: Write a null-terminated string pointed to by EDX
exit ; Irvine32: ExitProcess
main ENDP
END main
Je fais jeu Hangman donc je dois chercher dans le monde si avoir une lettre dans sa .. – SakaSerbia