Compilation: Determining whether two strings are equal to __ assembly

Source: Internet
Author: User

To determine whether two strings are equal output match or no match

Assume Cs:code,ds:data

Data segment

String1 db DUP (0)

string2 db DUP (0)

String3 db ' Please input string 1-by-space ', 0dh,0ah, ' $ '

String4 db 0dh,0ah, ' please input string 2-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; Display String 3

MOV ah,9

int 21h

MOV si,0

LOOP1:; Get string 1 save to 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:; Get string 2 save to 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; This sentence is most classic, by judging characters in the string1 encounter character 0 end

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

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.