MASTER OF COMPUTER APPLICATIONS
Course Code : MCS-012
Course Title : Computer Organisation and Assembly Language Programming
Assignment Number : MCA(1)/012/Assign/2014-15
Maximum Marks : 100
Weightage : 25%
Write a program in 8086 assembly Language (with proper comments) to count the number of those alphabets that are same as well as are at the same position in two different strings. For example, in case the strings are: “ABCDEFGHIJ” and “BDCDABCDEF”, this count is 2, as the 3rd and 4th positions in both the strings contain C and D, respectively. You may assume that both the strings are available in the memory and are of length 10. Make suitable assumptions, if any.
DATA SEGMENT
STR1 DB “ABCDEFGHIJ”
STR2 DB “BDCDABCDEF”
CNT DB 0H
MSG1 DB 10,13,’FISRT STRING IN MEMORY IS : $’
MSG2 DB 10,13,’SECOND STRING IN MEMORY IS : $’
MSG3 DB 10,13,’COUNT OF SAME POSITION EQUAL CHAR(S) IS : $’
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
DISPLAY STR1
DISPLAY MSG2
DISPLAY STR2
LEA SI,STR1
LEA DI,STR2
MOV CX,10
CHECK:
MOV AL,[SI]
CMP [DI],AL
JNE NOTEQU
INC CNT
NOTEQU: INC SI
INC DI
LOOP CHECK
DISPLAY MSG3
MOV DL,CNT
ADD DL,30H
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
program code :
[codesyntax lang=”asm” lines=”normal”]
DATA SEGMENT
STR1 DB “ABCDEFGHIJ”
STR2 DB “BDCDABCDEF”
CNT DB 0H
MSG1 DB 10,13,’FISRT STRING IN MEMORY IS : $’
MSG2 DB 10,13,’SECOND STRING IN MEMORY IS : $’
MSG3 DB 10,13,’COUNT OF SAME POSITION EQUAL CHAR(S) IS : $’
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
DISPLAY STR1
DISPLAY MSG2
DISPLAY STR2
LEA SI,STR1
LEA DI,STR2
MOV CX,10
CHECK:
MOV AL,[SI]
CMP [DI],AL
JNE NOTEQU
INC CNT
NOTEQU: INC SI
INC DI
LOOP CHECK
DISPLAY MSG3
MOV DL,CNT
ADD DL,30H
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
[/codesyntax]
Screen shots :-
After Execution :-