所以我有一个需要两个用户输入字符串的程序。一个要搜索,一个充满字符来搜索。该函数的代码如下:
.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:
,则打印结果字符串,然后多次打印string1,然后输入神秘字符。
我只需要打印结果字符串,但是我不确定这里是什么导致它不能单独打印。我最好的猜测是某种指针问题,但我并不乐观。