问题引入:
编写程序,统计字符串STRING中某个单词的个数,字符串以’$‘作为结束符,要统计的单词放在C_WORD中,统计结果存放在COUNT中。
例如:字符串为’adding that this is because of the large infrastructure investment, high operational and maintenance costs, and the old regulations governing prices.’
由于仅考虑了某一个单词在下一个字符是空格时被统计的情况,但像是逗号,句号,下一个字符是字母等情况因水平有限无法实现,还望慎重参考。
代码如下:
DATA segment
PARA DB "adding that this is because of the large infrastructure investment, high operational and maintenance costs, and the old regulations governing prices. $"
PARALEN = $-PARA
COUNT DB 0
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV CX,PARALEN
MOV BX,OFFSET PARA
alp:
MOV AL,[BX]
CMP AL,'a'
JNZ next
INC BX
MOV AL,[BX]
CMP AL,'n'
JNZ next
INC BX
MOV AL,[BX]
CMP AL,'d'
JNZ next
INC BX
MOV AL,[BX]
CMP AL,' '
JNZ next
JZ next1
next1:
INC COUNT
INC BX
LOOP alp
next:
INC BX
LOOP alp
MOV AH,4CH
INT 21H
code ends
end START
应付作业算是足够了吧 - -