Comparing strings in assembly using 8051 MCU

Discussion in 'Programmer's Corner' started by Dritech, Apr 28, 2015.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    Hi all,

    I need to compare a string which is saved in Code memory location starting from 200H with another three strings which are also saved in the Code memory location this time staring from 300H.

    The three strings will be separated by a comma to indicate different words and a full-stop will be used at the end of the words stream to indicate end of stream.

    For now I managed to save the string to be compared and the other three strings as follows:

    Code (Text):
    1. ORG 0000H
    2. MOV DPTR,#200H
    3. CLR A
    4. MOVC A,@A+DPTR
    5. MOV R0,A
    7. MOV DPTR,#300H
    8. CLR A
    9. MOVC A,@A+DPTR
    10. MOV R1,A
    12. //compare R0 to R1, compare the rest of the array characters
    14. Here: SJMP HERE
    17. ORG 200H
    18. MYDATA1: DB "abc"
    20.     ORG 300H
    21. MYDATA2: DB "ab,abc,abcd."
    22. END
    How can I continue comparing till I find a matching string?

    Any help would be highly appreciated as I have been searching the web for quite a while but still cannot manage to make it work.
  2. WBahn


    Mar 31, 2012
    This sounds like homework.

    How would you do it in a high-level language, like C, if the data was in two character arrays and you couldn't use any of the standard libraries?

    Also, what is the result supposed to be? Just a T/F indicating that the reference string was found in the stream? A count of how many times it was found? Do substring matches count?