Read a string from user until the user presses enter. Store the string in memory. Read another single character input from user and display the number of occurrences of this character in the string.
by assembly language
ans for the given problem
PROGRAM:
TXT1 DB 10,13,'ENTER ANY STRING :- $'
TXT2 DB 10,13,'ENTER ANY CHARACTER :- $'
TXT3 DB 10,13,' $'
TXT4 DB 10,13,'NO, CHARACTER FOUND IN THE GIVEN STRING $'
TXT5 DB ' CHARACTER(S) FOUND IN THE GIVEN STRING $'
CHAR DB ?
COUNT DB 0
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP ('$')
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 TXT1
LEA DX,P1
MOV AH,0AH
INT 21H
DISPLAY TXT2
MOV AH,1
INT 21H
MOV CHAR,AL
DISPLAY TXT3
LEA SI,P11
MOV CL,L1
MOV CH,0
CHECK:
MOV AL,[SI]
CMP CHAR,AL
JNE SKIP
INC COUNT
SKIP:
INC SI
LOOP CHECK
CMP COUNT,0
JE NOTFOUND
DISPLAY TXT3
MOV DL,COUNT
ADD DL,30H
MOV AH,2
INT 21H
DISPLAY TXT5
JMP EXIT
NOTFOUND:
DISPLAY TXT4
EXIT: MOV AH,4CH
INT 21H
CODE ENDS
END START
**************************Thank you***********************
Get Answers For Free
Most questions answered within 1 hours.