《電子技術(shù)應(yīng)用》
您所在的位置:首頁(yè) > 嵌入式技術(shù) > 解決方案 > 匯編源代碼之簡(jiǎn)單密碼輸入

匯編源代碼之簡(jiǎn)單密碼輸入

2017-07-23
關(guān)鍵詞: 匯編語(yǔ)言

title***簡(jiǎn)單密碼輸入 by lluct***
datasegment ;定義數(shù)據(jù)段
input  db   100 dup (?)
;定義輸入的字符串,字符串必須用db定義,長(zhǎng)度為100個(gè)字節(jié)
cmpare db   '5201314','$'
;定義密碼
msg1  db   'PASSWORD RIGHT!','$'
;定義輸入密碼正確后顯示出來(lái)的信息
msg2  db   'PASSWORD ERROR!','$'
;定義輸入密碼錯(cuò)誤后顯示出來(lái)的信息
headmsg db   'ENTER YOUR PASSWORD:','$'
;頭信息
dataends ;數(shù)據(jù)段結(jié)尾
  codesegment ;定義代碼段
assumecs:code ;規(guī)定cs的內(nèi)容
assumeds:data ;規(guī)定ds的內(nèi)容
  start:movax,data ;程序從start開(kāi)始
movds,ax ;ds置初值,data的段地址
movsi,0 ;變址寄存器置初值0
  call  enter ;調(diào)用顯示回車(chē)換行子程序
    lea   dx,headmsg;輸出頭信息字符串的偏移地址
    call  dispchs ;調(diào)用顯示字符串子程序
repeat:movah,01h 
;定義repeat標(biāo)號(hào),用于循環(huán)輸入單個(gè)字符.調(diào)用1號(hào)功能:從鍵盤(pán)輸入一個(gè)字符并回顯
int21h ;完成輸入回顯
    cmp   al,0dh ;輸入的字符和cr(回車(chē))比較
jefinish ;如果等于回車(chē)就轉(zhuǎn)移到finish
movinput[si],al;把a(bǔ)l的置傳送到input的si地址中(好像是這樣吧)
incsi ;si加1
jmprepeat ;無(wú)條件轉(zhuǎn)移到repeat
finish:movinput[si],24h;給輸入完成的字符串加上結(jié)束標(biāo)志($)
callenter
  mov   si,0 ;源變址寄存器置初值0
    mov   di,0 ;目的變址寄存器置初值0
    mov   cx,8 ;設(shè)置密碼檢查位數(shù)(結(jié)束標(biāo)志也要算進(jìn)去)
check: cmp   cx,0 ;置位數(shù)為0.
    je   right ;如果密碼檢查完成,轉(zhuǎn)移到right
    mov   bl,input[si];把input的si地址中的數(shù)據(jù)傳送到bl
    mov   dl,cmpare[di];把cmpare的di地址中的數(shù)據(jù)傳送到dl
    cmp   dl,bl ;dl和bl比較
    jne   error ;如果不相等,就轉(zhuǎn)移到error
    inc   si ;si加1
    inc   di ;di加1
    dec   cx ;cx減1
    jmp   check ;無(wú)條件轉(zhuǎn)移到check
  right: call  enter
    lea   dx,msg1 
    call  dispchs
    call  enter
    jmp   exit
  error: call  enter
    lea   dx,msg2
    call  dispchs
    mov   dl,07h ;輸出ascii碼的報(bào)警(響鈴)控制符bel(07h)
    call  dispch
    call  enter
    jmp   exit
exit:movah,4ch ;4c號(hào)功能調(diào)用:終止當(dāng)前程序并返回
int21h ;返回dos
  enterprocnear ;顯示回車(chē)換行子程序
movdl,0dh ;輸出ascii碼的回車(chē)控制符cr(odh)
calldispch
movdl,0ah ;輸出ascii碼的換行控制符lf(0ah)
calldispch
ret ;返回
enterendp ;子程序結(jié)尾
  dispchprocnear ;顯示單個(gè)字符子程序
movah,02h ;2號(hào)功能調(diào)用:顯示器輸出字符
int21h ;完成輸出顯示
ret
dispchendp
  dispchsprocnear ;顯示字符串子程序
movah,09h ;9號(hào)功能調(diào)用:顯示字符串
int21h ;完成輸出顯示
ret
dispchsendp
  codeends ;代碼段結(jié)尾
endstart ;結(jié)束匯編
  ;把以上代碼復(fù)制到記事本等文本程序中,并保存.(如passwrod.asm)
;編譯:masm password.asm
;連接:link password.obj
;執(zhí)行:password.exe
  =================================================================
  帶星號(hào)的密碼輸入
title***簡(jiǎn)單密碼輸入進(jìn)階 by lluct***
  datasegment ;定義數(shù)據(jù)段
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 2004 |',0dh,0ah
db'+----------------------------------------------+',0dh,0ah
    db   0dh,0ah,'PLEASE INPUT PASSWORD:','$'
;定義頭信息組
msg1db'PASSWORD RIGHT!','$'
;定義輸入密碼正確后顯示出來(lái)的信息
msg2db'PASSWORD ERROR!','$'
;定義輸入密碼錯(cuò)誤后顯示出來(lái)的信息
cmparedb'5201314','$'
;定義密碼
inputdb100 dup (?)
;定義輸入的字符串,字符串必須用db定義,長(zhǎng)度為100個(gè)字節(jié)
dataends ;數(shù)據(jù)段結(jié)尾
  codesegment ;定義代碼段
assumecs:code ;規(guī)定cs的內(nèi)容
assumeds:data ;規(guī)定ds的內(nèi)容
  start_program: ;程序從這里開(kāi)始
movax,data ;把data段地址賦給ax
movds,ax ;ds置初值,data的段地址
movsi,0 ;變址寄存器初值為0
  callenter ;調(diào)用顯示回車(chē)換行子程序
    lea   dx,headmsg;輸出頭信息組的偏移地址
calldispchs ;調(diào)用顯示字符串子程序
  repeat_input: ;循環(huán)輸入單個(gè)字符
movah,08h ;調(diào)用8號(hào)功能:鍵盤(pán)輸入字符(無(wú)回顯)
int21h ;完成輸入
    mov   dl,2ah ;輸出ascii碼的*號(hào)
    push  ax ;保護(hù)原來(lái)輸入的字符
    calldispch ;調(diào)用單個(gè)字符回顯子程序
    pop   ax ;恢復(fù)原來(lái)輸入的字符
    cmpal,0dh ;是否回車(chē)
jefinished_input;是就轉(zhuǎn)移到finished_input
movinput[si],al;保存單個(gè)字符
incsi ;訪問(wèn)下一個(gè)相對(duì)地址
jmprepeat_input;無(wú)條件轉(zhuǎn)移到repeat_input
  finished_input: ;完成輸出
movinput[si],24h;給剛才輸入的字符串加結(jié)束標(biāo)志($)
callenter
  movsi,0 ;si置0
movdi,0 ;di置0
movcx,8 ;設(shè)置檢測(cè)密碼的長(zhǎng)度,要包括結(jié)束標(biāo)志
check_password: ;檢測(cè)密碼
cmpcx,0 ;cx為是否為0
jeright ;是就轉(zhuǎn)移到right
movbl,input[si];把input的si的地址內(nèi)的信息傳送到bl
movdl,cmpare[di];把cmpare的di的地址內(nèi)的信息傳送到dl
cmpdl,bl ;檢查dl和bl是否一樣
jneerror ;不是就轉(zhuǎn)移到error
incsi ;si加1
incdi ;di加1
deccx ;cx減1
jmpcheck_password
  right:
call enter
leadx,msg1
calldispchs
callenter
jmpexit
  error:
callenter
leadx,msg2
calldispchs
movdl,07h ;輸出ascii碼的報(bào)警(響鈴)控制符bel(07h)
    call  dispch
callenter
jmpexit
  exit:  mov   ah,4ch ;4c號(hào)功能調(diào)用:終止當(dāng)前程序并返回
int21h ;返回dos
  enterprocnear ;顯示回車(chē)換行子程序
movdl,0dh ;輸出ascii碼的回車(chē)控制符cr
calldispch
movdl,0ah ;輸出ascii碼的換行控制符lf
calldispch
ret ;返回
enterendp
  dispchprocnear ;顯示單個(gè)字符子程序
    mov   ah,02h ;2號(hào)功能調(diào)用:顯示器輸出字符
int21h ;完成輸出顯示
    ret
dispchendp
  dispchsprocnear ;顯示字符串子程序
movah,09h ;9號(hào)功能調(diào)用:顯示字符串
int21h
ret
dispchsendp
  codeends ;代碼段結(jié)尾
    end   start_program;結(jié)束匯編
;把以上代碼復(fù)制到記事本等文本程序中,并保存.(如passwd2.asm)
;編譯:masm passwd2.asm
;連接:link passwd2.obj
;執(zhí)行:passwd2.exe

本站內(nèi)容除特別聲明的原創(chuàng)文章之外,轉(zhuǎn)載內(nèi)容只為傳遞更多信息,并不代表本網(wǎng)站贊同其觀點(diǎn),。轉(zhuǎn)載的所有的文章、圖片,、音/視頻文件等資料的版權(quán)歸版權(quán)所有權(quán)人所有,。本站采用的非本站原創(chuàng)文章及圖片等內(nèi)容無(wú)法一一聯(lián)系確認(rèn)版權(quán)者。如涉及作品內(nèi)容,、版權(quán)和其它問(wèn)題,,請(qǐng)及時(shí)通過(guò)電子郵件或電話通知我們,以便迅速采取適當(dāng)措施,,避免給雙方造成不必要的經(jīng)濟(jì)損失,。聯(lián)系電話:010-82306118;郵箱:[email protected],。