Итак, у меня есть программа, которая принимает две строки ввода пользователя. Один должен быть найден, а другой заполнен символами для поиска. Код для функции выглядит следующим образом:
.data
string1 DWORD 101 DUP(?),0
string2 DWORD 11 DUP(?),0
results DWORD 11 DUP(?),0
resultsStore DWORD 0,0
prompt1 BYTE "Enter your first String: ",0
prompt2 BYTE "Enter the chars to search: ",0
storeLoop DWORD 0
storeCount DWORD 0
.code
main PROC
mov edx, offset prompt1 ;moves the first prompt into edx
call writeString ;prints the first prompt
mov edx, offset string1 ;moves the first response into edx
mov ecx, 100 ;sets the limit for the first respsonse
call ReadString ;read user input into the first response
mov edx, offset prompt2 ;moves the second prompt into edx
call writeString ;prints the second prompt
mov edx, offset string2 ;moves the second response into edx
mov ecx, 10 ;seets the limit for the second response
call ReadString ;read user input into the second response
call checkMatch
call crlf
call WaitMsg
invoke ExitProcess,0
main ENDP
checkMatch PROC
L1:
mov ebx, storeCount ;store the count to access chars in string
mov storeLoop, ecx ;store the count running the outer loop
mov ah, BYTE ptr [edx+ecx] ;move individual char to al
inc ebx ;increment the position in the string
mov storeCount, ebx ;store the string position
mov edx, OFFSET string1 ;move string1 into edx
mov ebx, 0
L2:
mov al, BYTE ptr [edx+ebx] ;move the next char into al
cmp ah, al ;check if chars match
je match ;if yes, jump to match
inc ebx ;increment ebx
loop L2
jmp next
match:
mov ebx, resultsStore ;move next location in string to ebx
mov results[ebx*4], ecx ;store char in next open location
inc resultsStore ;increment the location of the next open spot
next:
mov ecx, storeLoop ;store the outer loop count
loop L1
mov edx, offset results
call writeString
ret
checkMatch ENDP
END main
Но когда я запускаю программу, она просто выводит один из этих вопросительных знаков в поле символов.
Интересно, если я добавлю строку call writeString
сразу после L1:
, будет напечатана строка результатов, затем несколько раз строка1, а затем загадочный символ.
Мне нужно просто напечатать строку результатов, но я не уверен, что здесь приводит к тому, что она не может быть напечатана сама по себе. Моя лучшая догадка - это проблема с указателем, но я не уверен.