下面的程序是统计输入字符串中单词saw的个数以及第一个出现的saw的偏移地址(以s的偏移地址输出)
问题是改成其它单词就有问题了。
以下为宏库文件MACROUT.LIB,需单独命名为扩展名为.LIB的文件,且与主程序保存在同一目录下。
OAH9 MACRO A
LEA DX,A
MOV AH,9
INT 21H
ENDM
OAH2 MACRO B
MOV DL,B
MOV AH,2
INT 21H
ENDM
HUIHUAN MACRO
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
ENDM
JIEWEI MACRO
MOV DL,'H'
MOV AH,2
INT 21H
MOV DL,20H
MOV AH,2
INT 21H
ENDM
OAH10 MACRO B
LEA DX,B
MOV AH,10
INT 21H
ENDM
OAH1 MACRO
MOV AH,1
INT 21H
ENDM
程序:
INCLUDE MACROUT.LIB
DATAS SEGMENT
BUF DB 200
DB ?
DB 200 DUP(?)
STR2 DB 'saw'
COUNT2 =$-STR2
COUNT DW ?
OUTPUT DB 'Please input a string:$ '
RESULT DB 0AH,0DH,0AH,0DH,'The number of saw is:'
FH1 DB 0
FH2 DB 0
FL1 DB 0
FL2 DB 0
ADDRESS DB 0AH,0DH,0AH,0DH,'The effective address is:'
EH1 DB 0
EH2 DB 0
EL1 DB 0
EL2 DB 0
AEND DB 0
ENDR DB '$'
DATAS ENDS
STACKS SEGMENT
DB 200 DUP(0)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,ES:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV ES,AX
MOV AL,[BUF+1]
SUB AL,COUNT2
ADD AL,1
MOV AH,0
MOV COUNT,AX
OAH9 OUTPUT
OAH10 BUF
CLD
LEA SI,BUF+2
MOV BX,SI
LP: LEA DI,STR2
MOV CX,COUNT2
REPE CMPSB
JE NT
INC BX
JMP ET
NT: INC DX
MOV BX,SI
CMP DX,1
JA ET
OUTA:
MOV CL,4
SUB BX,5
MOV AL,BL
MOV AH,BL
SHR AL,CL
ADD AL,30H
AND AH,0FH
ADD AH,30H
CMP AH,39H
JA ADD7
JMP OUTE
CMP2:CMP AL,39H
JA AD7
JMP OUTE
ADD7:ADD AH,7
JMP CMP2
AD7: ADD AL,7
OUTE:MOV EL1,AL
MOV EL2,AH
MOV AEND,'H'
MOV AL,BH
MOV AH,BH
SHR AL,CL
ADD AL,30H
AND AH,0FH
ADD AH,30H
MOV EH1,AL
MOV EH2,AH
ADD BX,5
ET: MOV SI,BX
CMP BX,COUNT
JBE LP
CMP DX,2
JNA OUT0
SUB DX,2
MOV CH,DH
MOV AL,DL
MOV AH,0
MOV CL,10
DIV CL
ADD AL,30H
ADD AH,30H
MOV FL1,AL
MOV FL2,AH
MOV AL,CH
MOV AH,0
MOV CL,10
DIV CL
ADD AL,30H
ADD AH,30H
MOV FH1,AL
MOV FH2,AH
OAH9 RESULT
JMP EXIT
OUT0:MOV FH1,'0'
MOV FH2,' '
MOV FL1,' '
MOV FL2,' '
MOV EH1,'N'
MOV EH2,'U'
MOV EL1,'L'
MOV EL2,'L'
MOV AEND,20H
OAH9 RESULT
EXIT:MOV AH,4CH
INT 21H
CODES ENDS
END START
[此贴子已经被作者于2007-6-25 10:24:38编辑过]