用emu8086编写程序实现账号、密码的注册和登录设置。要求: (1) 程序运行时首先提示“PLEASE INPUT ’L’ TO LOGIN OR ‘R’ TO REGISTRATION!” (2) 当输入’L’时,提示登录和输入密码,其中,密码输入时显示为******,登录账号或密码错误时提示出错。(可预置账号为lynu,密码为lynu2023); (3) 当输入’R’,提示注册账号,其中密码由6~8位数字和字母组成,组成错误提示重新输入密码。
时间: 2023-11-25 11:08:51 浏览: 38
以下是用emu8086编写的实现账号、密码的注册和登录设置的程序:
```
.model small
.stack
.data
user db "lynu", 0
password db "lynu2023", 0
buffer db 10, 0
input db 10, 0
welcome_msg db "PLEASE INPUT 'L' TO LOGIN OR 'R' TO REGISTRATION!", 0
login_msg db "LOGIN: ", 0
password_msg db "PASSWORD: ", 0
login_error_msg db "LOGIN ERROR!", 0
password_error_msg db "PASSWORD ERROR!", 0
register_msg db "REGISTRATION: ", 0
register_password_msg db "PASSWORD(MUST BE 6-8 DIGITS OR LETTERS): ", 0
register_error_msg db "REGISTRATION ERROR!", 0
.code
mov ax, @data
mov ds, ax
; display welcome message
lea dx, welcome_msg
mov ah, 09h
int 21h
; read input
mov ah, 01h
int 21h
mov bl, al
; login
cmp bl, 'L'
jne register
lea dx, login_msg
mov ah, 09h
int 21h
; read username
lea si, buffer
mov cx, 0
read_username:
mov ah, 01h
int 21h
cmp al, 0Dh ; enter key
je username_done
mov [si], al
inc si
inc cx
jmp read_username
username_done:
mov [si], 0
; read password
lea dx, password_msg
mov ah, 09h
int 21h
lea si, input
mov cx, 0
read_password:
mov ah, 08h ; read char without echo
int 21h
cmp al, 0Dh ; enter key
je password_done
cmp al, 08h ; backspace key
je backspace
mov [si], al
inc si
inc cx
cmp cx, 8 ; only allow 8 chars
je password_done
jmp read_password
backspace:
cmp cx, 0
je read_password
dec si
mov dl, ' '
mov ah, 02h
int 21h
mov dl, 08h
int 21h
dec cx
jmp read_password
password_done:
mov [si], 0
; check username and password
cmp user, buffer
jne login_error
cmp password, input
jne password_error
; login success
lea dx, "LOGIN SUCCESS!"
mov ah, 09h
int 21h
jmp exit
login_error:
lea dx, login_error_msg
jmp display_error
password_error:
lea dx, password_error_msg
jmp display_error
display_error:
mov ah, 09h
int 21h
jmp exit
; registration
register:
cmp bl, 'R'
jne exit
lea dx, register_msg
mov ah, 09h
int 21h
; read username
lea si, buffer
mov cx, 0
read_register_username:
mov ah, 01h
int 21h
cmp al, 0Dh ; enter key
je register_username_done
mov [si], al
inc si
inc cx
jmp read_register_username
register_username_done:
mov [si], 0
; read password
lea dx, register_password_msg
mov ah, 09h
int 21h
lea si, input
mov cx, 0
read_register_password:
mov ah, 08h ; read char without echo
int 21h
cmp al, 0Dh ; enter key
je register_password_done
cmp al, 08h ; backspace key
je register_backspace
cmp al, '0'
jb register_error
cmp al, '9'
jbe register_char_ok
cmp al, 'A'
jb register_error
cmp al, 'Z'
jbe register_char_ok
cmp al, 'a'
jb register_error
cmp al, 'z'
jbe register_char_ok
jmp register_error
register_char_ok:
mov [si], al
inc si
inc cx
cmp cx, 8 ; only allow 8 chars
je register_password_done
jmp read_register_password
register_backspace:
cmp cx, 0
je read_register_password
dec si
mov dl, ' '
mov ah, 02h
int 21h
mov dl, 08h
int 21h
dec cx
jmp read_register_password
register_password_done:
mov [si], 0
cmp cx, 5
jb register_error
cmp cx, 9
ja register_error
; registration success
mov user, buffer
mov password, input
lea dx, "REGISTRATION SUCCESS!"
mov ah, 09h
int 21h
jmp exit
register_error:
lea dx, register_error_msg
jmp display_error
; exit
exit:
mov ah, 4ch
int 21h
end
```
注意:该程序只是一个示例,需要根据实际需求进行修改和调整。