好友
阅读权限40
听众
最后登录1970-1-1
|
这是我写的第一个正式的汇编程序,代码如下: 基于masm,请在16位环境调试
ASSUME CS:CODE,DS:DATA,SS:STACK
DATA SEGMENT
MESSAGE DB 'Password:','$'
ERRORMSG DB 0DH,0AH,'Password Error!','$'
SUCCMSG DB 0DH,0AH,'Password Successful!','$'
BUF DB 'lizhirui','$'
DATA ENDS
STACK SEGMENT PARA STACK 'STACK'
DB 50 DUP(?)
STACK ENDS
CODE SEGMENT
START: ;输出Password:
MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV DX,OFFSET MESSAGE
MOV AH,9
INT 21H
MOV CL,0
AGAIN: ;接收键盘输入
MOV AH,7
INT 21H
CMP AL,1BH
JE EXIT
CMP AL,8;BACKSPACE
JE BACK
CMP AL,13;ENTER
JE CHECK
CMP AL,30H
JB ND
CMP AL,7AH
JA ND
CMP AL,40H
JB DISPLAY
CMP AL,60H
JA DISPLAY
AND AL,11011111B
ND:
JMP AGAIN
DISPLAY:
CMP CX,10
JE AGAIN
MOV AH,0
PUSH AX
INC CL
MOV AH,2
MOV DL,'*'
INT 21H
AND AL,11011111B
JMP AGAIN
EXIT:
MOV AH,4CH
INT 21H
BACK:;退格
CMP CL,0
JE AGAIN
POP DX
PUSH CX
MOV AH,03H
MOV BH,0
INT 10H
DEC DL
MOV AH,02H
MOV BH,0
INT 10H
POP CX
DEC CL
MOV AH,0AH
MOV AL,0
PUSH CX
MOV CX,1
INT 10H
POP CX
JMP AGAIN
ERROR:
MOV DX,OFFSET ERRORMSG
MOV AH,9
INT 21H
JMP EXIT
SUCC:
MOV DX,OFFSET SUCCMSG
MOV AH,9
INT 21H
JMP EXIT
CHECK:
MOV CH,0
CMP CL,8
JNZ ERROR
MOV BX,OFFSET BUF
ADD BX,7
s: POP DX
MOV AX,DS:[BX]
DEC BX
CMP AL,DL
JNZ ERROR
LOOP s
JMP SUCC
CODE ENDS
END START
|
|