Assembly: Determine if two strings are equal (match)

Publisher:dong125612Latest update time:2015-05-26 Source: 51heiKeywords:assembly Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
;Program to input two strings from the keyboard into the memory buffer and compare whether the two strings are the same;
;If they are the same, output 'match'; if they are different, output 'no match'.
;The modified code can loop through
DATAS SEGMENT
 data1 DB 100 DUP(?)
 data2 DB 100 DUP(?)
 string DB 0DH,0AH,'$'
 tital1 DB 'Please input the first string :',0DH,0AH,'$'
 tital2 DB 'Please input the second string :',0DH,0AH,'$'
 tital3 db 'Do you want to have a try again(if yes,input y, else input n ): ',0dh,0ah,'$'
    result1 db 'match',0dh,0ah,'$'
    result2 db 'no match',0dh,0ah,'$'  
 temp DW 0 
DATAS ENDS
CODES SEGMENT
 ASSUME CS:CODES,DS:DATAS
START: MOV AX,DATAS
    MOV DS,AX
    MOV si,0
tip1: ;Output header 1
 LEA dx,tital1
 MOV ah,09h 
 INT 21H
first: ; input the first string
 MOV ah,01h ; input characters are placed in AL
 INT 21H ; end with carriage return
 cmp al,0dh
 je tip2 
 MOV data1[si],AL ; save in memory
 INC si
 JMP first
tip2:
 LEA dx,string
 MOV AH,09H
 INT 21H
 MOV temp,si ; save si so that the next string can be compared with it
 MOV si,0 ; output header 2 
 LEA dx,tital2 MOV ah,09h  INT 21H second: ; input the second string  MOV AH,01H ; input characters are placed in AL  INT 21H ; also end with carriage return  CMP AL,0DH  je output              mov data2[si],al ; save in memory  inc si
 jmp   second output:  LEA dx,string  MOV AH,09H  INT 21H  CMP temp,si ;Judge whether the lengths are equal  JNE nomatch  MOV si,0 pipei:MOV AL,DATA1[si];Judge whether each character is equal  MOV AH,DATA2[si]  INC si  CMP AL,AH  JNE nomatch  CMP si,temp  JE MATCH  JMP pipei MATCH: LEA DX,result1 ;If no match, output conclusion 1      MOV AH,09H      INT 21H      JMP EXIT nomatch:LEA DX,result2 ;If match, output conclusion 2   MOV AH,09H   INT 21H EXIT: ;Ask whether to continue      lea dx,tital3      mov ah,09h      int 21h       mov ah,01h      int 21h      cmp al,'y'      lea dx,string      mov ah,09h          int 21h      je start      cmp al,'n'      je over      jmp exit over: ;End MOV AH,4CH   INT 21H CODES ENDS  END START













































        




Keywords:assembly Reference address:Assembly: Determine if two strings are equal (match)

Previous article:Implementing quick sorting with VC++ class (and outputting the process)
Next article:Assembly: Count the number of various characters in a string

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号