首页 > 解决方案 > 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,然后添加神秘字符。

我只需要打印结果字符串,但我不确定这里是什么导致它无法自行打印。我最好的猜测是某种指针问题,但我并不肯定。

标签: assemblyx86masmirvine32

解决方案


推荐阅读