Assembly Program to Compare two Strings
This program takes two strings from the user and tells whether the strings are equal or not. This program will work for strings of up to 100 characters because I have declared STRING1 and STRING2 of size 100.
The program will take the first string and store it in STRING1 and then ask to enter the second string and store the second string in STRING2 after getting both strings this program will compare both strings character by character.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | .MODEL SMALL .STACK 100H .DATA MSG1 DB "ENTER STRING 1: $" MSG2 DB 0DH, 0AH, "ENTER STRING 2: $" STRING1 DB 100 DUP(?) STRING2 DB 100 DUP(?) EQUALMSG DB 0DH, 0AH, "STRINGS ARE EQUAL $" NOTEQUALMSG DB 0DH, 0AH, "STRINGS ARE NOT EQUAL $" .CODE MAIN PROC MOV AX, @DATA MOV DS, AX MOV ES, AX MOV AH, 9 LEA DX, MSG1 INT 21H LEA DI, STRING1 MOV AH, 1 READ1: INT 21H CMP AL, 0DH JE ENDOFSTRING1 STOSB JMP READ1 ENDOFSTRING1: MOV AL, "$" STOSB MOV AH, 9 LEA DX, MSG2 INT 21H LEA DI, STRING2 MOV AH, 1 READ2: INT 21H CMP AL, 0DH JE ENDOFSTRING2 STOSB JMP READ2 ENDOFSTRING2: MOV AL, "$" STOSB LEA SI, STRING1 LEA DI, STRING2 MOV BX, 0 COMPARE: MOV AH, STRING1[BX] MOV AL, STRING2[BX] CMP AH, "$" JE EQUAL CMP AH, AL JNE NOTEQUAL INC BX JMP COMPARE EQUAL: CMP AL, "$" JNE NOTEQUAL MOV AH, 9 LEA DX, EQUALMSG INT 21H JMP EXIT NOTEQUAL: MOV AH, 9 LEA DX, NOTEQUALMSG INT 21H EXIT: MAIN ENDP END MAIN |
No comments