Counting letters and printing an array of numbers with windows api

橙三吉。 提交于 2019-12-11 17:23:22

问题


I have an user input string, which was lowercased and all special characters removed target2 and I want to count how many times each letter appears on the string, and then print the array with 26 letters. However, it prints just a blank line. Is the error when I add to the array? when I print from the array, or both?

If I watch letterArray, it says 1 '\x1' What does that mean?

lettersArray byte 26 dup(0)


countingLetters proc
  ; clear esi and edi
  mov esi, 0
  mov edi, 0

  charloop
    mov al, target2[esi]               ; Get a character from the string
    cmp al, 97                   ; Check if its not a letter
    jb printloop                ; If bellow, print
    sub eax, 97                  ; so that 'a' = 0, 'z' = 26.
    mov dl, lettersArray[eax]
    inc dl
    mov lettersArray[eax], dl
    inc esi
    jmp charloop                ; repeat


    printloop:
    mov bl, lettersArray[edx * type lettersArray]
    add bl, 48
    push edx
    invoke WriteConsoleA, consoleOutHandle, ebx, 4, bytesWritten, 0
    pop edx
    inc edx
    cmp edx, 25                 ;Are we done?
    ja  done                    ;if yes
    jmp printloop               ; Repeat
  done:
  ret 
countingLetters endp

This should count the appearances of each letter and print an array with 26 elements, i.e: 00102000000000[etc]

来源:https://stackoverflow.com/questions/57347621/counting-letters-and-printing-an-array-of-numbers-with-windows-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!