Assembly Comparing Strings

Posted on 2005-04-23
Last Modified: 2012-05-05
I need some help comparing strings, i need to do some functions with this strings

the first one is union of two strings

for example {1,2,3,4} union {5,6,4} = {1,2,3,4,5,6}

so i was looking for a way to compare each number to see if its located in the other string
and therefore be able to create the last string.

the strings are stored in a stack and the first two are the ones that need to be compared in other to do the union function

thanks for your help =)
Question by:basura
    LVL 11

    Expert Comment

    use cmpsb

    since the operands are ds:si and es:di, make sure the data seg and the extra segment point to the same thing for example

    mov ax, @data
    mov ds, ax
    mov es, ax

    mov si, OFFSET string1      ;ds:si
    mov di, OFFSET string2     ;es:di

    mov cx, strlen

    repe  cmpsb

    jb Less
    ja Greater
    je Equal

       ;do something
       jmp END

       jmp ENd
    LVL 11

    Accepted Solution

    I forgot to mention if you have to get the strings from the stack you can do

    push bp
    mov bp, sp

    mov si, Offset [SS:bp+08]   ; get the right most param
    mov di offset  [ss:bp+04]    ;get the left argument

    Author Comment

    Haven't tried the code
    But forgot to mention that it  should be for NASM for windows/dos
    LVL 11

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Intel DX58SO board 7 837
    Binary Bomb/GDB Questions 10 1,857
    FSM's, Flow Charts or Something else 5 363
    cmpl in assembly 5 1,290
    After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
    In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now