用8086设计编写程序实现账号、密码的注册和登录设置。要求:(1)程序运行时首先提示“PLEASEINPUT’L’TOLOGINOR‘R’TOREGISTRATION!”(2)当输入’L’时,提示登录和输入密码,其中,密码输入时显示为******,登录账号或密码错误时提示出错。(可预置账号为lynu,密码为lynu2023);(3)当输入’R’,提示注册账号,其中密码由6~8位数字和字母组成,组成错误提示重新输入密码。
时间: 2023-11-25 07:08:24 浏览: 39
好的,以下是用 8086 汇编语言编写的示例程序:
```assembly
.model small
.stack 100h
.data
username db 10, 0
password db 10, 0
error_msg db "Username or password incorrect! Please try again.", 0
reg_success_msg db "Registration success!", 0
login_success_msg db "Login success!", 0
input_username_msg db "Please input your username: $"
input_password_msg db "Please input your password: $"
input_choice_msg db "PLEASE INPUT 'L' TO LOGIN OR 'R' TO REGISTRATION! $"
input_reg_username_msg db "Please input your username: $"
input_reg_password_msg db "Please input your password (6-8 characters): $"
invalid_choice_msg db "Invalid choice! Please try again. $"
password_mask db "*", 0
.code
mov ax, @data
mov ds, ax
; Prompt for choice
mov ah, 9
lea dx, input_choice_msg
int 21h
; Get choice
mov ah, 1
int 21h
cmp al, 'R'
je register
cmp al, 'L'
je login
lea dx, invalid_choice_msg
jmp print_error
register:
; Prompt for username
mov ah, 9
lea dx, input_reg_username_msg
int 21h
; Get username
mov ah, 0Ah
lea dx, username
int 21h
; Prompt for password
mov ah, 9
lea dx, input_reg_password_msg
int 21h
; Get password
mov ah, 0Ah
lea dx, password
int 21h
; Validate password
mov si, offset password+1
mov cx, 8
xor bh, bh
check_password_loop:
mov al, byte ptr [si]
cmp al, '0'
jb invalid_password
cmp al, '9'
ja check_uppercase
inc si
loop check_password_loop
check_uppercase:
mov si, offset password+1
mov cx, 8
xor bh, bh
check_uppercase_loop:
mov al, byte ptr [si]
cmp al, 'A'
jb invalid_password
cmp al, 'Z'
ja check_lowercase
inc si
loop check_uppercase_loop
check_lowercase:
mov si, offset password+1
mov cx, 8
xor bh, bh
check_lowercase_loop:
mov al, byte ptr [si]
cmp al, 'a'
jb invalid_password
cmp al, 'z'
ja invalid_password
inc si
loop check_lowercase_loop
; Registration success
mov ah, 9
lea dx, reg_success_msg
int 21h
jmp exit
login:
; Prompt for username
mov ah, 9
lea dx, input_username_msg
int 21h
; Get username
mov ah, 0Ah
lea dx, username
int 21h
; Prompt for password
mov ah, 9
lea dx, input_password_msg
int 21h
; Get password
mov ah, 0
lea dx, password
mov cl, 10
mov bh, 0
print_password_loop:
mov ah, 8
int 21h
mov bl, al
cmp bl, 13
je end_print_password
mov al, password_mask
mov ah, 0Eh
int 10h
mov byte ptr [si], bl
inc si
dec cl
jmp print_password_loop
end_print_password:
mov byte ptr [si], 0
; Validate login
mov si, offset password+1
mov cx, 8
xor bh, bh
check_login_loop:
mov al, byte ptr [si]
cmp al, '0'
jb invalid_login
cmp al, '9'
ja check_login_uppercase
inc si
loop check_login_loop
check_login_uppercase:
mov si, offset password+1
mov cx, 8
xor bh, bh
check_login_uppercase_loop:
mov al, byte ptr [si]
cmp al, 'A'
jb invalid_login
cmp al, 'Z'
ja check_login_lowercase
inc si
loop check_login_uppercase_loop
check_login_lowercase:
mov si, offset password+1
mov cx, 8
xor bh, bh
check_login_lowercase_loop:
mov al, byte ptr [si]
cmp al, 'a'
jb invalid_login
cmp al, 'z'
ja invalid_login
inc si
loop check_login_lowercase_loop
; Login success
mov ah, 9
lea dx, login_success_msg
int 21h
jmp exit
invalid_password:
mov si, offset input_reg_password_msg
jmp print_error
invalid_login:
mov si, offset input_password_msg
jmp print_error
print_error:
mov ah, 9
lea dx, error_msg
int 21h
jmp login
exit:
mov ah, 4Ch
int 21h
end
```
运行程序后,根据提示输入 L 或 R 进行登录或注册操作。若选择注册操作,则需要输入用户名和密码,其中密码需要符合 6-8 个字符的要求;若选择登录操作,则需要输入预置的用户名和密码。在输入密码时,由于安全考虑,密码会显示为星号。如果用户名或密码不正确,则会提示出错。如果登录成功,则会输出 Login success! 的信息。注意,由于 8086 CPU 的限制,这个程序只能处理单个账户和密码,无法支持多个账户注册和登录。
阅读全文