彙編:判斷兩個字串是否相等__彙編

來源:互聯網
上載者:User

;判斷兩個字串是否相等相等輸出match 否則no match

assume cs:code,ds:data

 

data segment

string1 db 100 dup(0)

string2 db 100 dup(0)

string3 db 'please input string 1 end by space',0dh,0ah,'$'

string4 db 0dh,0ah,'please input string 2 end by space','$'

string5 db 0dh,0ah,'match$'

string6 db 0dh,0ah,'no match$'

data ends

 

code segment

start:

mov ax,data  

mov ds,ax

lea dx,string3;顯示字串3

mov ah,9

int 21h

mov si,0

loop1:            ;獲得字串1儲存到string1

mov ah,1

int 21h

mov string1[si],al

cmp al,20H

je k1

add si,1 

loop loop1

k1:       

lea dx,string4

mov ah,9

int 21h

mov dl,0ah

mov ah,2

int 21h

mov dl,0dh

mov ah,2

int 21h

mov si,0     

loop2:       ;獲得字串2儲存到string2

mov ah,1

int 21h

mov string2[si],al

cmp al,20h

je k2

add si,1 

loop loop2

k2: 

mov si,0

loop3:

mov al,string1[si]

mov bl,string2[si]

cmp al,bl

jne k5

cmp string1[si],20h ;這句最經典,通過判斷string1中的字元遇到字元0結束

je k4

add si,1 

loop loop3

k4:

lea dx,string5

mov ah,9

int 21h

jmp k6

k5:

lea dx,string6

mov ah,9

int 21h 

k6:

mov ah,4ch

int 21h

code ends

end start

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.