Assembly source code Simple password input

Source: Internet
Author: User
Tags exit header terminates
title*** simple password input by lluct***
Datasegment, defining data segments
Input db dup (?)
Define the input string, the string must be defined in db with a length of 100 bytes
Cmpare db ' 5201314 ', ' $ '
; Define a password
MSG1 db ' PASSWORD right! ', ' $ '
To define the information that is displayed when the password is entered correctly
MSG2 db ' PASSWORD error! ', ' $ '
To define the information that is displayed when you enter a password error
Headmsg db ' ENTER YOUR PASSWORD: ', ' $ '
; Header information
Dataends End of data segment
codesegment; Define Code Snippets
Assumecs:code the content of CS
Assumeds:data the content of a DS
Start:movax,data program starting from start
Movds,ax;d S initial value, section address of data
movsi,0, variable address register set initial value 0
Call enter; Invoke show carriage return newline subroutine
Lea Dx,headmsg; offset address of the output header information string
Call Dispchs; invoke display string subroutine
repeat:movah,01h
Define the repeat label, which is used to loop through a single character. Call 1th: Enter a character from the keyboard and echo back
int21h; complete input echo
CMP AL,0DH; input character and Cr (carriage return) comparison
Jefinish, if it's equal to return, transfer to finish.
Movinput[si],al: Send Al's place to the SI address of input (like this)
Incsi si plus 1
Jmprepeat, unconditional transfer to repeat
finish:movinput[si],24h the string that completes the input with the end sign ($)
Callenter
mov si,0; Source Change address register set initial value 0
MOV di,0; purpose Change address register place initial value 0
mov cx,8; set password check digits (end sign also counted)
CHECK:CMP cx,0; The number of digits is 0.
Je Right; if the password check is complete, move to right
mov bl,input[si]; transfer data from SI address of input to BL
mov Dl,cmpare[di]; transfer data from Cmpare's di address to DL
CMP DL,BL;d L and BL comparisons
Jne error; If not equal, transfer to error
Inc SI + 1
Inc di;d I plus 1
Dec CX; CX minus 1
JMP check, unconditional transfer to check
Right:call Enter
Lea DX,MSG1
Call Dispchs
Call Enter
JMP exit
Error:call Enter
Lea DX,MSG2
Call Dispchs
mov dl,07h; output ASCII alarm (Bell) control character Bel (07h)
Call DISPCH
Call Enter
JMP exit
EXIT:MOVAH,4CH 4c Function Call: Terminates the current program and returns
int21h; return to Dos
enterprocnear; show carriage return newline subroutine
MOVDL,0DH, return controller CR (ODH) for output ASCII
Calldispch
MOVDL,0AH: LF (0ah), the newline control for the output ASCII code
Calldispch
To return to a ret;
ENTERENDP the end of a child program
Dispchprocnear display a single word subcode program
MOVAH,02H 2nd function Call: Display output characters
INT21H, complete output display
Ret
Dispchendp
Dispchsprocnear; display String subroutine
movah,09h 9th Function Call: Display string
INT21H, complete output display
Ret
Dispchsendp
codeends; end of code snippet
EndStart; closing assembly
; Copy the above code into a text program such as Notepad and save it. (e.g. Passwrod.asm)
; Compiling: MASM password.asm
; Connection: Link password.obj
; implementation: Password.exe
=================================================================
Password input with an asterisk
title*** simple Password input step by lluct***
Datasegment, defining data segments
Headmsg db ', 0dh,0ah
DB ' +----------------------------------------------+ ', 0dh,0ah
DB ' | Simple input Password system for ASM program | ', 0dh,0ah
DB ' |        Have a fun. ^-^. | ', 0dh,0ah
DB ' | Poor programmer:lluct date:march,21 | ', 0dh,0ah
DB ' +----------------------------------------------+ ', 0dh,0ah
DB 0dh,0ah, ' please INPUT PASSWORD: ', ' $ '
; Define header information groups
Msg1db ' PASSWORD right! ', ' $ '
To define the information that is displayed when the password is entered correctly
Msg2db ' PASSWORD error! ', ' $ '
To define the information that is displayed when you enter a password error
Cmparedb ' 5201314 ', ' $ '
; Define a password
Inputdb100 DUP (?)
Define the input string, the string must be defined in db with a length of 100 bytes
Dataends End of data segment
codesegment; Define Code Snippets
Assumecs:code the content of CS
Assumeds:data the content of a DS
Start_program:; The program starts here.
Movax,data; Assign the data segment address to AX
Movds,ax;d S initial value, section address of data
movsi,0 the initial value of the variable address register is 0.
Callenter; Call show carriage return newline subroutine
Lea Dx,headmsg; offset address of the output header information group
Calldispchs; Call display String subroutine
Repeat_input:; Loops Enter a single character
movah,08h Call 8th function: Keyboard input character (no echo)
int21h, complete input
MOV dl,2ah; * Number of ASCII code output
Push ax; Protect the characters that were originally entered
CALLDISPCH, calling a single word echo subroutine
Pop ax to restore the characters that were originally entered
CMPAL,0DH; Enter or not
Jefinished_input is transferred to Finished_input.
Movinput[si],al; Save a single character
INCSI; access Next relative address
Jmprepeat_input, unconditional transfer to Repeat_input
Finished_input:; finish output
movinput[si],24h; Give the string you just entered the end sign ($)
Callenter
movsi,0 Si 0
movdi,0;d I 0
movcx,8 to set the length of the detection password to include the end flag
Check_password:; detection password
cmpcx,0 CX is 0
Jeright is transferred to right.
MOVBL,INPUT[SI]; transfer information from the SI address of input to BL
MOVDL,CMPARE[DI]; Transfer information from the address of Cmpare di to DL
CMPDL,BL check whether DL and BL are the same
Jneerror, not just transferred to the error
Incsi si plus 1
INCDI;d I plus 1
DECCX CX minus 1
Jmpcheck_password
Right
Call Enter
Leadx,msg1
Calldispchs
Callenter
Jmpexit
Error
Callenter
Leadx,msg2
Calldispchs
movdl,07h output ASCII alarm (Bell) control character Bel (07h)
Call DISPCH
Callenter
Jmpexit
Exit:mov ah,4ch 4c Function Call: Terminates the current program and returns
int21h; return to Dos
enterprocnear; show carriage return newline subroutine
MOVDL,0DH, return controller CR for output ASCII
Calldispch
Movdl,0ah the newline control character of the output ASCII LF
Calldispch
To return to a ret;
Enterendp
Dispchprocnear display a single word subcode program
MOV ah,02h 2nd number function call: Display output characters
INT21H, complete output display
Ret
Dispchendp
Dispchsprocnear; display String subroutine
movah,09h 9th Function Call: Display string
int21h
Ret
Dispchsendp
codeends; end of code snippet
End Start_program Assembly
; Copy the above code into a text program such as Notepad and save it. (e.g. Passwd2.asm)
; Compiling: MASM passwd2.asm
; Connection: Link passwd2.obj
; implementation: Passwd2.exe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.