汇编实现回文判断

不多说,直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
DATA    SEGMENT  
Prompt DB 'Please enter a string:$'
YesStr DB 13, 10, 'This string is palindrome$'
NoStr DB 13, 10, 'This string is not palindrome$'
Input DB 128, ?, 128 DUP(0)
DATA ENDS
STACK SEGMENT
DB 128 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STACK
MAIN:
MOV AX, DATA
MOV DS, AX
MOV DX, offset Prompt
MOV AH, 09H
INT 21H
;
MOV DX, OFFSET Input
MOV AH, 0AH
INT 21H
;
MOV DI, OFFSET Input
MOV SI, OFFSET Input


XOR CX, CX
MOV CL, [DI+1]
ADD DI, 2
ADD SI, 2
DEC CX
ADD DI, CX
;force DI point to the last word of Input
AGAIN:
CMP SI, DI
JA TESSKIP
MOV AH, byte ptr [SI]
MOV AL, byte ptr [DI]
CMP AH, AL
JNE NOSKIP
INC SI
DEC DI
JMP AGAIN
TESSKIP:
MOV DX, OFFSET YesStr
MOV AH, 09H
INT 21H
JMP ENDSKPI
;

NOSKIP:
MOV DX, OFFSET NoStr
MOV AH, 09H
INT 21H
;
ENDSKPI:
MOV AH, 4CH
INT 21H

CODE ENDS
END MAIN
坚持原创文章分享,您的支持将鼓励我继续创作!