An Assembly Language program to count number of alphabets are same – IGNOU MCA Assignment 2014-15

By | July 18, 2014

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 :

  1. DATA SEGMENT
  2. STR1 DB "ABCDEFGHIJ"
  3. STR2 DB "BDCDABCDEF"
  4. CNT DB 0H
  5. MSG1 DB 10,13,'FISRT STRING IN MEMORY IS : $'
  6. MSG2 DB 10,13,'SECOND STRING IN MEMORY IS : $'
  7. MSG3 DB 10,13,'COUNT OF SAME POSITION EQUAL CHAR(S) IS : $'
  8. DATA ENDS
  9. DISPLAY MACRO MSG
  10. MOV AH,9
  11. LEA DX,MSG
  12. INT 21H
  13. ENDM
  14. CODE SEGMENT
  15. ASSUME CS:CODE,DS:DATA
  16. START:
  17. MOV AX,DATA
  18. MOV DS,AX
  19. DISPLAY MSG1
  20. DISPLAY STR1
  21. DISPLAY MSG2
  22. DISPLAY STR2
  23. LEA SI,STR1
  24. LEA DI,STR2
  25. MOV CX,10
  26. CHECK:
  27. MOV AL,[SI]
  28. CMP [DI],AL
  29. JNE NOTEQU
  30. INC CNT
  31. NOTEQU: INC SI
  32. INC DI
  33. LOOP CHECK
  34. DISPLAY MSG3
  35. MOV DL,CNT
  36. ADD DL,30H
  37. MOV AH,2
  38. INT 21H
  39. MOV AH,4CH
  40. INT 21H
  41. CODE ENDS
  42. END START

Screen shots :-

Asm_program_String_Compare

After Execution :-

Asm_program_String_Compare_Output

Leave a Reply