用masm5.0编译汇编语言,实现两个字符串的比较,为什么我输入的字符会被覆盖几个?
我输入的是123456789,前边的12345被覆盖了。DATASEGMENTSTR1DB'INPUT',0DH,0AH,'$'STR2DB'MATCH',0DH,0AH...
我输入的是123456789,前边的12345被覆盖了。
DATA SEGMENT
STR1 DB 'INPUT',0DH,0AH,'$'
STR2 DB 'MATCH',0DH,0AH,'$'
STR3 DB 'NO MATCH',0DH,0AH,'$'
BUF1 DB 20,?,20 DUP(?)
BUF2 DB 20,?,20 DUP(?)
HH DB 0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,DATA
MOV ES,AX
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF1
MOV AH,0AH
INT 21H
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF2
MOV AH,0AH
INT 21H
MOV CL,BUF1+2
AND CX,0FH
LEA SI,BUF1+2
LEA DI,BUF2+2
AGAIN: CMPSB
JNE NO
LOOP AGAIN
YES: LEA DX,STR2
MOV AH,09H
INT 21H
JMP STOP
NO: LEA DX,STR3
MOV AH,09H
INT 21H
STOP: MOV AH,4CH
INT 21H
CODE ENDS
END START 展开
DATA SEGMENT
STR1 DB 'INPUT',0DH,0AH,'$'
STR2 DB 'MATCH',0DH,0AH,'$'
STR3 DB 'NO MATCH',0DH,0AH,'$'
BUF1 DB 20,?,20 DUP(?)
BUF2 DB 20,?,20 DUP(?)
HH DB 0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,DATA
MOV ES,AX
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF1
MOV AH,0AH
INT 21H
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF2
MOV AH,0AH
INT 21H
MOV CL,BUF1+2
AND CX,0FH
LEA SI,BUF1+2
LEA DI,BUF2+2
AGAIN: CMPSB
JNE NO
LOOP AGAIN
YES: LEA DX,STR2
MOV AH,09H
INT 21H
JMP STOP
NO: LEA DX,STR3
MOV AH,09H
INT 21H
STOP: MOV AH,4CH
INT 21H
CODE ENDS
END START 展开
展开全部
因为你再输出提示消息的时候没有换行,所以覆盖了原来输入的内容
简单修改就是显示输出提示消息的时候输出回车换行就可以了
主要是:
STR1 DB 0DH,0AH,'INPUT',0DH,0AH,'$'
STR2 DB 0DH,0AH,'MATCH',0DH,0AH,'$'
STR3 DB 0DH,0AH,'NO MATCH',0DH,0AH,'$'
改过的完整代码如下:
DATA SEGMENT
STR1 DB 0DH,0AH,'INPUT',0DH,0AH,'$'
STR2 DB 0DH,0AH,'MATCH',0DH,0AH,'$'
STR3 DB 0DH,0AH,'NO MATCH',0DH,0AH,'$'
BUF1 DB 20,?,20 DUP(?)
BUF2 DB 20,?,20 DUP(?)
HH DB 0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,DATA
MOV ES,AX
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF1
MOV AH,0AH
INT 21H
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF2
MOV AH,0AH
INT 21H
MOV CL,BUF1+2
AND CX,0FH
LEA SI,BUF1+2
LEA DI,BUF2+2
AGAIN: CMPSB
JNE NO
LOOP AGAIN
YES: LEA DX,STR2
MOV AH,09H
INT 21H
JMP STOP
NO: LEA DX,STR3
MOV AH,09H
INT 21H
STOP: MOV AH,4CH
INT 21H
CODE ENDS
END START
简单修改就是显示输出提示消息的时候输出回车换行就可以了
主要是:
STR1 DB 0DH,0AH,'INPUT',0DH,0AH,'$'
STR2 DB 0DH,0AH,'MATCH',0DH,0AH,'$'
STR3 DB 0DH,0AH,'NO MATCH',0DH,0AH,'$'
改过的完整代码如下:
DATA SEGMENT
STR1 DB 0DH,0AH,'INPUT',0DH,0AH,'$'
STR2 DB 0DH,0AH,'MATCH',0DH,0AH,'$'
STR3 DB 0DH,0AH,'NO MATCH',0DH,0AH,'$'
BUF1 DB 20,?,20 DUP(?)
BUF2 DB 20,?,20 DUP(?)
HH DB 0DH,0AH,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,DATA
MOV ES,AX
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF1
MOV AH,0AH
INT 21H
LEA DX,STR1
MOV AH,09H
INT 21H
LEA DX,BUF2
MOV AH,0AH
INT 21H
MOV CL,BUF1+2
AND CX,0FH
LEA SI,BUF1+2
LEA DI,BUF2+2
AGAIN: CMPSB
JNE NO
LOOP AGAIN
YES: LEA DX,STR2
MOV AH,09H
INT 21H
JMP STOP
NO: LEA DX,STR3
MOV AH,09H
INT 21H
STOP: MOV AH,4CH
INT 21H
CODE ENDS
END START
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询