This is a small experiment we want to do when learning the compilation. It feels interesting and I want to post it to my blog. For more information, see.
Lab requirements:
After the program is executed, an operation prompt is displayed. Enter the user name and password. When you type the password, the program does not display the entered characters, the welcome page is displayed and DOS is returned only when the user name, password string, and program string are the same.
The Code contains detailed comments. If you are interested, you can check them out.
Code:
; Filename: exercise2.asm. 486 Data Segment use16 mesg1 dB 0dh, 0ah, 'Please input Username: $'mesg2 dB 0dh, 0ah, 'Please input password: $'mesg3 dB 0dh, 0ah, 'login incorrect! $ 'Username db' b12040331 $ 'password db' 123456789 $ 'flag DB? Buf dB 30 dB? DB 30 DUP (?) Data ends code segment use16 assume Cs: code, DS: Data beg: mov ax, data mov ds, ax mov es, ax Aga: mov flag, 0 mov ah, 9; display prompt information (User Name) mov dx, offset mesg1 int 21 h mov ah, 0ah; enter user name mov dx, offset Buf int 21 h mov BL, BUF + 1 mov BH, 0 mov Si, offset BUF + 2 mov byte PTR [bx + Si], '$' mov Si, offset BUF + 2; Verify that the user name is correct mov Di, offset username mov CX, 9 CLD repe cmpsb mov flag, CL mov ah, 9; display prompt information (password) mov dx, offset mesg2 int 21 h mov Si, offset BUF + 2; process input password input: moV ah, 0ch; clear Keyboard Buffer int 21 h mov ah, 8 int 21 h CMP Al, 13 JZ next mov [Si], Al Inc Si mov ah, 2 mov DL, 2ah int 21 h JMP input next: CMP flag, 0 jnz lerror mov Si, offset BUF + 2; verify if the password is correct mov Di, offset password mov CX, 9 CLD repe cmpsb jnz lerror mov ah, 4ch int 21 h lerror: mov ah, 9 mov dx, offset mesg3 int 21 h JMP agacode ends end beg
The running effect is as follows:
A compilation Applet: user login verification program