0% found this document useful (0 votes)
21 views3 pages

MP 10

Uploaded by

hetavimodi2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

MP 10

Uploaded by

hetavimodi2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 10

SOURCE CODE:
%macro read_stdin_terminos ;macro to read stdin_terminos
mov eax, 36h
mov ebx, 0
mov ecx, 5401h
mov edx, terminos ;terminos to buffer defined in bss section
int 80h ;where data in stdin_terminos is stored after readin
%endmacro

%macro write_stdin_terminos ;macro to write stdin_terminos


mov eax, 36h
mov ebx, 0
mov ecx, 5402h
mov edx, terminus
int 80h
%endmacro

Section .data
asterisk db “*” ;character to display in place of entered key
enterkey db 10 ;ASCII code of enter key
pwd db “123” ;password set in program as ‘123’
correct db “access granted”, 10 ;message to be displayed id password is correct
correctlen equ $-correct
incorrect db “access denied”, 10 ;message to be displayed id password is incorrect
incorrectlen equ $-incorrect

section .bss
key reb 2 ;store entered keys here one by one
pwdbyuser resb 24 ;buffer for storing entered password
terminus resb 36 ;buffer for storing terminos structure

section .text
global start
_start:
read_stdin_terminos ;read terminos structure
mov eax, 0AH ;make echo & canonical mode off
not eax ;0AH becomes F5H
and [terminus+12], eax ;only 4th & 2nd bit is set to 0
write_stdin_terminos ;write back terminos structure
mov esi, 0 ;esi to pointer used to store keys in buffer ‘pwdbyuser’

getpasswordkeys:
mov eax, 3 ;read a key pressed by user
mov ebx, 0 ;but it will not be displayed on screen since echo is turned OFF
mov ecx, key ;save it in buffer key
mov edx, 1
int 80h
mov al, byte[key] ;take that key in al
cmp al, 10 ;& check it it is enter key
je passwordenterd ;if equal to enter key, then go for checking the password
mov byte[pwdbyuser + esi], al ;else save it in location pwdbyuser one by one
mov edx, 1 ;display * on screen instead of key pressed by user
mov ecx, asterisk
mov eax, 4
mov ebx, 1
int 80h
inc esi ;point esi to next location in buffer ‘pwdbyuser’
jmp getpasswordkeys ;go back to accept next key

passwordenterd:
mov cx, 3 ;since stored password 123 has three characters
mov esi, pwdbyuser ;esi points to password entered by user
mov edi, pwd ;edi points to password stored in the program

keepchecking:
mov al, [esi] ;take a character pointed by esi into al
mov bl, [edi] ;take a character pointed by edi into bl
cmp al, bl ;compare them
jne disp_incorrect ;if not equal then go to part which displays access denied
inc esi ;else increment esi to point to next character in user password
inc edi ;& increment edi to point to next character in stored password
dec cx ;decrement character counter which is in cx
jnz keepchecking

mov rax, 1 ;so display message “access granted”


mov rdi, 1
mov rsi, correct
mov rdx, correctlen
syscall
jmp skip ;skip next block which displays message “access denied”

disp_incorrect:
mov rax, 1 ;display message “access denied”
mov rdi, 1
mov rsi, incorrect
mov rdx, incorrectlen
syscall
skip:
read_stdin_terminos ;read terminos structure
or dword[terminos + 12], 0AH ;make canonical & echo mode ON by
;ORing with 0Ah
write_stdin_terminos ;which makes terminos structure

mov eax, 1 ;exit the program


mov ebx, 0
int 80h
00
OUTPUT:

You might also like