An Assembly language program that counts the occurrence of alphabet A (irrespective of case) in a string – IGNOU MCA Assignment 2015 – 16

By | August 18, 2015

BACHELOR OF COMPUTER APPLICATIONS

 

Course Code : BCSL-022
Course Title : Assembly Language Programming Lab
Assignment Number : BCA(II)/L-022/Assignment/2015
Maximum Marks : 50
Weightage : 25%

 

Write and run an Assembly language program that counts the occurrence of alphabet A (irrespective of case) in a sting. For example, for the string AXabAYaf, the output will be 4. You may assume that the string is available in the memory and output is stored in the AL register. 

 

DATA SEGMENT
STR1 DB “AXabAYaf”
A DB 0H
MSG1 DB 10,13,”COUNT OF A’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

LEA SI,STR1

MOV CX,10
CHECK:
MOV AL,[SI]
CMP AL,’A’
JNE N1
INC A
N1:
CMP AL,’a’
JNE N2
INC A

N2: INC SI
LOOP CHECK

MOV AL,A

DISPLAY MSG1

MOV DL,A
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 "AXabAYaf"
  3. A DB 0H
  4. MSG1 DB 10,13,"COUNT OF A's IS : $"
  5. DATA ENDS
  6. DISPLAY MACRO MSG
  7. MOV AH,9
  8. LEA DX,MSG
  9. INT 21H
  10. ENDM
  11. CODE SEGMENT
  12. ASSUME CS:CODE,DS:DATA
  13. START:
  14. MOV AX,DATA
  15. MOV DS,AX
  16. LEA SI,STR1
  17. MOV CX,10
  18. CHECK:
  19. MOV AL,[SI]
  20. CMP AL,'A'
  21. JNE N1
  22. INC A
  23. N1:
  24. CMP AL,'a'
  25. JNE N2
  26. INC A
  27. N2: INC SI
  28. LOOP CHECK
  29. MOV AL,A
  30. DISPLAY MSG1
  31. MOV DL,A
  32. ADD DL,30H
  33. MOV AH,2
  34. INT 21H
  35. MOV AH,4CH
  36. INT 21H
  37. CODE ENDS
  38. END START

Screen shots :-

Asm_program_Count_Aa_in_String

After Execution :

Asm_program_Count_Aa_in_String_Output