我正在尝试将字符串拆分为单词&检查字符串中单词的频率。
问题在于,当我尝试使用" Space"来分割字符串时作为分隔符,第一个单词存储在新数组中,之后字符串不会复制到下一个字符串。
这是我到目前为止所做的代码。这个程序将一个字符串作为输入并打印出该单词的出现次数。
INCLUDE Irvine32.inc
.data
;declaring the variables for processign
aString BYTE ?
singleWords BYTE 51 DUP (?)
indexArray BYTE 51 DUP (?)
counterArray BYTE 51 DUP (?)
wordIndex BYTE ?
counterIndex BYTE ?
mycount BYTE ?
.code
main PROC
; Providing offset of the aString variable where the string will be save after ; the readString method is called
mov edx, OFFSET aString
mov ecx, 50 ;buffer size - 1
call ReadString
; making the counter 0 for loop
; and then passing the length of the string for processing
; wordIndex is used to save the index where the space occur to later on loop
; through that much characters in singleWords array
; counter index is just for checking the loop is working
mov ecx, 0
mov esi, 0
mov edi, 0
mov wordIndex, 0
mov counterIndex, 0
mov mycount, 0
mov ecx, eax
Loop1:
CMP ecx, 0 ;compare if the string is empty so stop the loop
JE L03
mov al, aString[esi] ;passing the characters to al for space ;checking
CMP al, 32
JE L01
mov singleWords[esi], al ; if not space then copy the character to ;singleWords array
INC esi
INC mycount
INC wordIndex
DEC ecx
JMP Loop1
L01:
mov bl, wordIndex ; if sapce occur pass the index to bl
mov indexArray[edi], bl ; save the index in indexArray
INC edi
INC esi
INC mycount
INC wordIndex
DEC ecx
JMP Loop1
L03:
mov edx,OFFSET singleWords
call Writestring
movzx eax, mycount
call WriteDec
call Crlf
exit
main ENDP
END main