我试图创建一个单词计数器(计算字符串中有多少单词),我使用jmp
指令返回WORDCOUNT
标签,但问题是它不断循环。当我在jmp WORDCOUNT
之前添加ADDCOUNTER
时,它会产生无限循环。可能是什么原因造成的?如果有人能向我解释,我真的很感激。 :)
; count the number of words in the string
mov ax, 0000
mov bx, 0000 ; will contain the data
mov cx, 0000 ; will count the number of words
mov dx, 0000 ; erase all content to 0000
lea bx, USERSTRING ; bx will contain the user string input
WORDCOUNT:
mov al, [bx] ; al will contain bx data inside
cmp al, "$" ; check if it is the end of the string already
je ENDWORDCOUNT ; get out of the loop if done
cmp al, " " ; if the value has space 20h
je ADDCOUNTER ; then go to ADDCOUNTER to add
inc bx ; hop to the next address one at a time
jmp WORDCOUNT
ADDCOUNTER:
inc cx ; add cx with 1 because it means there is space
jmp WORDCOUNT
ENDWORDCOUNT:
call TODECIMAL
mov cx, ax ; ax transfers the decimal version here
mov word ptr HOWMANYWORDS, cx ; this one will be turned into a decimal dude help me here huhuhu
lea dx, HOWMANYWORDS
call PRINTF
答案 0 :(得分:1)
当你找到空格字符时,你会跳到ADDCOUNTER
,在那里你增加cx
而不是bx
,所以一旦跳回到WORDCOUNT
你就会成为inc bx
永远地读同一个角色(即空间),等等
您ADDCOUNTER
案件中也需要{{1}}。