assembly - MASM 打印未知字符
问题描述
所以我有一个程序需要两个用户输入字符串。一个要搜索,一个充满字符要搜索。该函数的代码如下:
.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,然后添加神秘字符。
我只需要打印结果字符串,但我不确定这里是什么导致它无法自行打印。我最好的猜测是某种指针问题,但我并不肯定。
解决方案
推荐阅读
- php - 比较php中的日期并显示结果
- json - 如何将 JSON 数据加载到 Angular 中的类或类数组中?
- python - 如何使用 Python 读取文本文件并传输到字典?
- javascript - 冻结网站元素直到时间过去
- excel - 为什么在使用 Flynsarmy csv 播种器包时从 Excel 导出到 Csv 会导致 Laravel Seeder 静默失败?
- r - Shiny:使用 selectizeInput 选择组
- php - 如何在laravel中为票务系统创建模型之间的关系
- android - 如何在保持更新的同时通过whatsapp发送我的位置?
- matlab - Matlab中如何防止物体被camlight照亮?
- java - 使用 gson 从文件夹中读取文件