题目要求:录入一字符串,判断该字符串是否为回文.
1,如果字符串中含有非字母字符,判定时忽略不记;
2,判定回文时,字母不分大小写;
3,判定回文时,如果字符个数为0,或为1,则判为回文;
4,如果为回文,在屏幕上输出"YES!";如果不是回文,则输出"NO!".
源程序如下:
STACK SEGMENT
DB 200 DUP(0)
STACK ENDS
DATA SEGMENT
BUF1 DB '$'
BUF2 DB 'YES!',0AH,0DH,'$'
BUF3 DB 'NO!',0AH,0DH,'$'
BUF DB 100 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START: MOV AX,DATA
MOV DS,AX
WRITE MACRO A
PUSH AX
PUSH DX
LEA DX,A
MOV AH,9
INT 21H
POP DX
POP AX
ENDM
MOV CX,0
LEA SI,BUF
MOV DI,SI
WRITE BUF1
A: MOV AH,1
INT 21H
CMP AL,65
JL B
CMP AL,90
JNG C
CMP AL,97
JL B
CMP AL,122
JG B
JMP C
B: CMP AL,0DH
JE D
JMP A
C: MOV [DI],AL
INC CX
INC DI
JMP A
D: CALL CRLF
CALL CRLF
MOV DX,1
DEC DI
CMP CX,0
JZ F
I: CMP SI,DI
JZ F
PUSH SI
DEC SI
CMP SI,DI
JZ F
POP SI
MOV AH,BYTE PTR [SI]
CMP AH,BYTE PTR [DI]
JZ G
ADD AH,32
CMP AH,BYTE PTR [DI]
JZ G
SUB AH,64
CMP AH,BYTE PTR [DI]
JZ G
JMP H
F: MOV DX,1
JMP EXIT1
G: INC SI
DEC DI
JMP I
H: MOV DX,0
EXIT1: CMP DX,1
JZ E
WRITE BUF3
JMP EXIT
E: WRITE BUF2
EXIT: MOV AH,4CH
INT 21H
CRLF PROC
PUSH AX
PUSH DX
MOV AH,2
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
POP DX
POP AX
RET
CRLF ENDP
CODE ENDS
END START
阅读(2484) | 评论(0) | 转发(0) |