;password.asm
.MODEL SMALL
.STACK 100h
.DATA
pass DB 'HELL','$'
prompt DB 0Ah, 0Dh,'Enter Password:','$'
tries DB 'Number of tries left:','$'
wrongpass DB 'Sorry that was incorrect, please try again','$'
notriesleft DB 'Sorry, you have used up all your tries','$'
correct DB 'Correct, access granted','$'
.CODE
mov ax,@data ; points to data segment in memory
mov ds,ax ; moves ax to ds register
mov ah,09h ; move print instruction to ah
mov dx,OFFSET prompt ; move OFFSET of prompt to dx register
int 21h ; check data segment address then get offset address to display mesg
mov ch,3 ; set counter for number of tries
inputloop:
cmp ch, 0 ; is number of tries value zero?
je fail ; if yes jump to end
mov cl, 4 ; set counter for number of characters
mov ah,08h ; take character input without echo function
int 21h ; execute input character function
push ax ; push inputted character onto stack
mov ah, 2Ah ; move asterix(*) into ah
int 21h ; display asterix
dec cl ; decrement number of characters counter
cmp cl, 0 ; test to see if user has inputted 4 characters
je checkpass ; if 4 characters have been inputted jump to test
jne inputloop ; if 4 characters have not been inputted jump back to start of loop
checkpass:
dec ch ; decrement the number of tries counter by 1
pop bx ; move inputted character from stack to bx
cmp [pass+3], bx ; compare memory location 'L' with value in bx
jne inputloop ; if not equal jump back to inputloop start
pop bx ; move inputted character from stack to bx
cmp [pass+2], bx ; compare memory location 'L' with value in bx
jne inputloop ; if not equal jump back to inputloop start
pop bx ; move inputted character from stack to bx
cmp [pass+1], bx ; compare memory location 'E' with value in bx
jne inputloop ; if not equal jump back to inputloop start
pop bx ; move inputted character from stack to bx
cmp [pass+0], bx ; compare memory location 'H' with value in bx
jne inputloop ; if not equal jump back to inputloop start
jmp success ; if all compares match, password is correct, jump to success message
fail:
mov ah,09h ; move dos function display into ah
mov dx, OFFSET notriesleft ; move offset of incorrect to dx register
int 21h ; execute function and display fail message
jmp finish ; jump to end of program
success: ; success jump start
mov ah,09h ; move print function into ah
mov dx, OFFSET correct ; move message into dx register
int 21h ; execute DOS function to display message
finish:
mov ah,4ch ; end the program
int 21h ; same as above
END