我有两个字符串和一个字母。
selectedWords BYTE "BICYCLE"
guessWords BYTE "-------"
inputLetter BYTE 'C'
基于this answers,如果selectedWords有字母C,我会编写代码,如果是这样,他需要更改字符串guessWords:
guessWords“--C-C - ”
但是从一些奇怪的原因我得到了所有其他可能性,只是不正确。关于如何解决这个问题的一些建议。
答案 0 :(得分:1)
首先,忘记所谓的字符串指令(scas,comps,movs)。其次,您需要一个带索引的固定指针(dispkacement),例如[esi+ebx]
。您是否认为WriteString
需要以空字符结尾的字符串?
INCLUDE Irvine32.inc
.DATA
selectedWords BYTE "BICYCLE"
guessWords BYTE SIZEOF selectedWords DUP ('-'), 0 ; With null-termination for WriteString
inputLetter BYTE 'C'
.CODE
main PROC
mov esi, offset selectedWords ; Source
mov edi, offset guessWords ; Destination
mov ecx, LENGTHOF selectedWords ; Number of bytes to check
mov al, inputLetter ; Search for that character
xor ebx, ebx ; Index EBX = 0
ride_hard_loop:
cmp [esi+ebx], al ; Compare memory/register
jne @F ; Skip next line if no match
mov [edi+ebx], al ; Hang 'em lower
@@:
inc ebx ; Increment pointer
dec ecx ; Decrement counter
jne ride_hard_loop ; Jump if ECX != 0
mov edx, edi
call WriteString ; Irvine32: Write a null-terminated string pointed to by EDX
exit ; Irvine32: ExitProcess
main ENDP
END main