Article directory
1. Experimental purpose and requirements
1. Master the writing of cycle programs and the method of ending the cycle.
2. Master the usage of DOS and BIOS function calls.
2. Experimental content
After the implementation program of the user login verification program is executed, a prompt operation is given, asking the user to type in the user name and password; when the user types in the password, the program does not echo the typed characters; only when the user typed in the user name, password string and the program default When the character strings are the same, the welcome interface is displayed and DOS is returned; otherwise, a prompt message is given, and the user name or password is wrong, and input again. Interface color customization (color or black and white)
3. Experimental environment (experimental equipment)
XP/WIN7+MASM/TASM/Easy Assembly/Future Assembly
4. Experiment code
.586
DATA SEGMENT USE16
MESG1 DB 'INPUT YOUR USERNAME: $' ;提示字符
MESG2 DB 'INPUT YOUR PASSWORD: $'
ERROR DB '-----USERNAME OR PASSWORD ERROR!----$'
WELCOME DB '---------------WELCOME!-------------$'
_USERNAME DB 'root'
_PASSWORD DB 'root'
_ULEN EQU $-_USERNAME ; 用户名长度
_PLEN EQU $-_PASSWORD ; 密码长度
USERNAME DB 15 ; 输入的用户名
PASSWORD DB 15 DUP(?) ; 输入的密码
PLEN DB 0 ; 输入密码的长度
DATA ENDS
CODE SEGMENT USE16
ASSUME CS: CODE, DS: DATA
BEG: MOV AX, DATA
MOV DS, AX
NEXT0: MOV AH, 9 ;09H功能号,显示DS:DL内字符串
MOV DX, OFFSET MESG1
INT 21H
MOV AH, 0AH ;键盘输入字符串并显示,存在U缓冲区
MOV DX, OFFSET USERNAME ;用户输入字符串起始偏移位置放入DX缓冲区
INT 21H
MOV AH, 2
MOV DL, 0AH ;换行字符
INT 21H
MOV AH, 9 ;显示提示字符串
MOV DX, OFFSET MESG2
INT 21H
MOV CX, _PLEN
MOV SI, OFFSET PASSWORD ;把输入密码起始偏移地址放入SI
NEXT1: MOV AH, 07H ;无回显从键盘读入一个字符
INT 21H
CMP AL, 0DH ;判断输入是否结束
JE IND
MOV [SI], AL ;将输入密码字符放入数据区:PWD
MOV AH, 2 ;每输入一位密码显示一个‘*’
MOV DL, '*'
INT 21H
INC PLEN
INC SI
JMP NEXT1
IND: MOV AH, 2 ;输出换行
MOV DL, 0AH
INT 21H
MOV BX, OFFSET USERNAME+1 ;[BX]=实际输入字符数
MOV AL, [BX]
CMP AL, _ULEN ;比较用户名长度
MOV BX, OFFSET _USERNAME
MOV SI, OFFSET _USERNAME+2
MOV CX, _ULEN ;设置循环次数
NEXT2: MOV AL, [BX]
CMP [SI], AL ;循环比较用户名是否正确
INC SI
INC BX
LOOP NEXT2
MOV BX, OFFSET _PASSWORD
MOV SI, OFFSET PASSWORD
MOV CL, PLEN
MOV CH, 0
CMP CX, _PLEN ;比较密码长度
JNZ ERR
MOV CX, _PLEN
NEXT3: MOV AL, [BX]
CMP [SI], AL ;循环比较密码字符是否正确
JNZ ERR
INC SI
INC BX
LOOP NEXT3
JMP WEL
ERR: MOV AH, 9
MOV DX, OFFSET ERROR ;输出用户名或密码错误提示
INT 21H
MOV AH, 2
MOV DL, 0AH
INT 21H
JMP NEXT0
WEL: MOV AH, 9 ;输出登录成功的提示
MOV DX, OFFSET WELCOME
INT 21H
JMP EXIT
EXIT: MOV AH, 4CH
INT 21H
CODE ENDS
END BEG
5. Experimental process description and result analysis
1. After the program is executed, a prompt operation is given, and the user is asked to enter the user name and password.
2. When the user types in the password, the program will not echo the typed characters; only when the user name and password string typed by the user are the same as the default string in the program, the welcome interface will be displayed and DOS will be returned; 3. Otherwise, a prompt message will be given
. Username or password is wrong, please enter again.
6. Experimental summary (including problems and solutions, experience, opinions and suggestions, etc.)
1. Pay attention to the use of sub-function calling methods
2. The naming format of variables should be unified and concise
3. The use of program counter CX