【发布时间】:2014-10-18 09:38:17
【问题描述】:
我试图创建一个单词计数器(计算字符串中有多少个单词),我使用 jmp 指令返回到 WORDCOUNT 标签,但问题是它不断产生无限环形。当我在ADDCOUNTER 之前添加jmp WORDCOUNT 时,它会形成一个无限循环。这可能是什么原因?如果有人可以向我解释,我将不胜感激。 :)
; 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
【问题讨论】:
标签: loops assembly word infinite tasm