Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to compare two strings

Posted By: Ludwik Fischer     Category: Assembly Language     Views: 7948

Write a Program to compare two strings.

Code for Program to compare two strings in Assembly Language

Data Segment
  str1 db 'GLSICT','$'  
  strlen1 db $-str1
  str2 db 'GLSICT','$'
  strlen2 db $-str2
  streq db 'Strings are Equal','$'
  struneq db 'Strings are Unequal','$'
Data Ends

Code Segment
  Assume cs:code, ds:data
  Begin:
    mov ax, data
    mov ds, ax
    mov es, ax
    lea si, str1   
    lea di, str2
    mov cx, 6
    mov al, strlen1
    mov bl, strlen2
    cmp al, bl
    jne Not_Equal

    repe cmpsb
    jne Not_Equal
    jmp Equal

    Not_Equal:
       mov ah, 09h
       lea dx, struneq
       int 21h
       jmp Exit
    Equal:
       mov ah, 09h
       lea dx, streq
       int 21h
    Exit:
       mov ax, 4c00h
       int 21h
Code Ends
End Begin

  
Share: 


Didn't find what you were looking for? Find more on Program to compare two strings Or get search suggestion and latest updates.

Ludwik Fischer
Ludwik Fischer author of Program to compare two strings is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!