assembly x86(nasm)串比较
生活随笔
收集整理的這篇文章主要介紹了
assembly x86(nasm)串比较
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
預(yù)留字符串口令,輸入口令串與預(yù)留密碼串比較。若匹配則顯示“MATCH!CONGRATULATION”,否則顯示“NOMATCH!”,并讓用戶重新輸入,程序能對口令進行測試,但測試次數(shù)最多3次,若3次輸入密碼皆錯,給出相應(yīng)的提示信息,程序退出。
?
兩種做法:
data segment message db 'This is a sample program of passward'db 0dh,0ah,'Please strike the key!',0dh,0ah,'$' passward db 'huangchangsheng$' buf1 db 20db ?db 20 dup('$') FAULT db 0dh,0ah,'NOMATCH!Please enter again!',0dh,0ah,'$' RIGHT db 0dh,0ah,'MATCH!CONGRATULATION!',0dh,0ah,'$' ending db 0dh,0ah,'You have typed the wrong passward for three times!',0dh,0ah,'$' data ends code segment assume cs:code,ds:data start: mov ax,datamov ds,ax mov dx,offset message mov ah,9 int 21h mov cl,3jmp input rinput: mov dx,offset FAULT ;提示錯誤mov ah,9 int 21h input: lea dx, buf1 ;字符串輸入mov ah, 0ah int 21hxor si,si strcmp: ;串比較mov al,passward[si]cmp al,'$'jz output2mov al,passward[si] cmp buf1[si+2],aljnz output1inc sijmp strcmp output1: loop rinputmov dx,offset ending mov ah,9 int 21hjmp exit output2: mov dx,offset RIGHT ;提示正確mov ah,9 int 21h exit: mov ah,4ch int 21h code ends end start第二種比較難受,因為di和附加段搞了好久,然后是看大佬代碼才發(fā)現(xiàn)自己錯哪了的
https://blog.csdn.net/pengwill97/article/details/79249631傳送門
data segment message db 'This is a sample program of passward'db 0dh,0ah,'Please strike the key!',0dh,0ah,'$' buf1 db 20,?,20 dup('$') FAULT db 0dh,0ah,'NOMATCH!Please enter again!',0dh,0ah,'$' RIGHT db 0dh,0ah,'MATCH!CONGRATULATION!',0dh,0ah,'$' ending db 0dh,0ah,'You have typed the wrong passward for three times!',0dh,0ah,'$' data ends ext segment passward db 'huangchangsheng$' ext ends code segment assume cs:code,ds:data,es:ext start: mov ax,datamov ds,axmov ax,extmov es,ax mov dx,offset message mov ah,9 int 21h mov cx,3jmp input rinput: mov dx,offset FAULT ;提示錯誤mov ah,9 int 21h input: lea dx, buf1 ;字符串輸入mov ah, 0ah int 21hlea di,passwardlea si,buf1+2push cxmov cl,buf1+1repz cmpsb ;當(dāng)前字符相同則繼續(xù)循環(huán)jz output2jnz output1 output1:pop cxloop rinputmov dx,offset ending mov ah,9 int 21hjmp exit output2: mov dx,offset RIGHT ;提示正確mov ah,9 int 21h exit: mov ah,4ch int 21h code ends end start如果使用repz cmpsb,密碼應(yīng)該放在附加段,不然可能會出bug,原因可能是di是目的變址寄存器,可用來存放相對于 ES 段之目的變址指針。?
?
轉(zhuǎn)載于:https://www.cnblogs.com/lanclot-/p/10963477.html
總結(jié)
以上是生活随笔為你收集整理的assembly x86(nasm)串比较的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx 优化详解
- 下一篇: git 常用操作命令(Common op