;Ben Weir ;CIS 35 ;Assignment 2 .model small .stack 100h .data pass1 db 'CRAMP' pass2 db 'PRINT' pass3 db 'DANCE' usrpass db 0ah dup (0) wrongmsg db 0ah, 0dh, 'Invalid Password, Access Denied!$' rightmsg db 0ah, 0dh, 'Password Valid, Access Permitted!$' prompt db 0ah, 0dh, 'Enter the Password: $' .code mov ax, @data mov ds, ax mov es, ax ;set up DS, ES lea dx, prompt mov ah, 9h int 21h ;prompt user for password lea si, usrpass mov cx, 0ah call readstring ;get password cmp ax, 5 jnz wrong ;make sure the password is 5 long lea si, pass1 call comparestr cmp cx, 0 ;test first password jz right lea si, pass2 call comparestr cmp cx, 0 ;test second password jz right lea si, pass3 call comparestr cmp cx, 0 ;test third password jz right wrong: lea dx, wrongmsg jmp displaymsg right: lea dx, rightmsg displaymsg: mov ah, 9h ;show whether they got it right or not int 21h done: mov ax, 4c00h ;terminate program int 21h comparestr proc near ;enter with si: pointer to string to compare to user entered string ;returns cx: 0 if strings match, >0 if they don't match push di lea di, usrpass mov cx, 6 repz cmpsb pop di ret comparestr endp readstring proc near ;enter with cx: number of characters to read ; si: offset of place to store string ;returns ax: number of chars entered push cx push si mov bx, si ;save starting address newchar: mov ah, 8 ;char input without echo int 21h cmp al, 0dh jz stringdone ;exit if they press enter cmp al, 8 jz backspace ;don't add the character if it's BS mov dl, al mov ah, 2 int 21h ;show character mov [si], al inc si loop newchar jmp stringdone backspace: cmp si, bx ;don't want to backspace jle nomorebs ;past start of string dec si mov byte ptr [si], 0 mov ah, 2 mov dl, 8 int 21h mov dl, 20h ;erase character with ' ' and another BS int 21h mov dl, 8 int 21h nomorebs: cmp cx, 0 jnz newchar stringdone: mov ax, si sub ax, bx pop si pop cx ret readstring endp end